<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>perlos2 - Perl under OS/2, DOS, Win0.3*, Win0.95 and WinNT. - Perldoc Browser</title>
    <link rel="search" href="https://perldoc.perl.org/opensearch.xml" type="application/opensearchdescription+xml" title="Perldoc Browser">
    <link rel="canonical" href="https://perldoc.perl.org/perlos2">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/styles/stackoverflow-light.min.css" integrity="sha512-cG1IdFxqipi3gqLmksLtuk13C+hBa57a6zpWxMeoY3Q9O6ooFxq50DayCdm0QrDgZjMUn23z/0PMZlgft7Yp5Q==" crossorigin="anonymous" />
    <style>
      body {
        background: #f4f4f5;
        color: #020202;
      }
      .navbar-dark {
        background-image: -webkit-linear-gradient(top, #005f85 0, #002e49 100%);
        background-image: -o-linear-gradient(top, #005f85 0, #002e49 100%);
        background-image: linear-gradient(to bottom, #005f85 0, #002e49 100%);
        filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff005f85', endColorstr='#ff002e49', GradientType=0);
        background-repeat: repeat-x;
      }
      .navbar-dark .navbar-nav .nav-link,
      .navbar-dark .navbar-nav .nav-link:focus { color: #fff }
      .navbar-dark .navbar-nav .nav-link:hover { color: #ffef68 }
      #wrapperlicious {
        margin: 0 auto;
        font: 0.9em 'Helvetica Neue', Helvetica, sans-serif;
        font-weight: normal;
        line-height: 1.5em;
        margin: 0;
        padding: 0;
      }
      #wrapperlicious h1 { font-size: 1.5em }
      #wrapperlicious h2 { font-size: 1.3em }
      #wrapperlicious h3 { font-size: 1.1em }
      #wrapperlicious h4 { font-size: 0.9em }
      #wrapperlicious h1, #wrapperlicious h2, #wrapperlicious h3,
      #wrapperlicious h4, #wrapperlicious dt {
        color: #020202;
        margin-top: 1em;
        margin-bottom: 1em;
        position: relative;
        font-weight: bold;
      }
      #wrapperlicious a { color: inherit; text-decoration: underline }
      #wrapperlicious #toc { text-decoration: none }
      #wrapperlicious a:hover { color: #2a2a2a }
      #wrapperlicious a img { border: 0 }
      #wrapperlicious :not(pre) > code {
        color: inherit;
        background-color: rgba(0, 0, 0, 0.04);
        border-radius: 3px;
        font: 0.9em Consolas, Menlo, Monaco, monospace;
        padding: 0.3em;
      }
      #wrapperlicious dd {
        margin: 0;
        margin-left: 2em;
      }
      #wrapperlicious dt {
        color: #2a2a2a;
        font-weight: bold;
        margin-left: 0.9em;
      }
      #wrapperlicious p {
        margin-bottom: 1em;
        margin-top: 1em;
      }
      #wrapperlicious li > p {
        margin-bottom: 0;
        margin-top: 0;
      }
      #wrapperlicious pre {
        border: 1px solid #c1c1c1;
        border-radius: 3px;
        font: 100% Consolas, Menlo, Monaco, monospace;
        margin-bottom: 1em;
        margin-top: 1em;
      }
      #wrapperlicious pre > code {
        display: block;
        background-color: #f6f6f6;
        font: 0.9em Consolas, Menlo, Monaco, monospace;
        line-height: 1.5em;
        text-align: left;
        white-space: pre;
        padding: 1em;
      }
      #wrapperlicious dl, #wrapperlicious ol, #wrapperlicious ul {
        margin-bottom: 1em;
        margin-top: 1em;
      }
      #wrapperlicious ul {
        list-style-type: square;
      }
      #wrapperlicious ul ul {
        margin-bottom: 0px;
        margin-top: 0px;
      }
      #footer {
        font-size: 0.8em;
        padding-top: 0.5em;
        text-align: center;
      }
      #more {
        display: inline;
        font-size: 0.8em;
      }
      #perldocdiv {
        background-color: #fff;
        border: 1px solid #c1c1c1;
        border-bottom-left-radius: 5px;
        border-bottom-right-radius: 5px;
        margin-left: auto;
        margin-right: auto;
        padding: 3em;
        padding-top: 1em;
        max-width: 960px;
      }
      #moduleversion { float: right }
      #wrapperlicious .leading-notice {
        font-style: italic;
        padding-left: 1em;
        margin-top: 1em;
        margin-bottom: 1em;
      }
      #wrapperlicious .permalink {
        display: none;
        left: -0.75em;
        position: absolute;
        padding-right: 0.25em;
        text-decoration: none;
      }
      #wrapperlicious h1:hover .permalink, #wrapperlicious h2:hover .permalink,
      #wrapperlicious h3:hover .permalink, #wrapperlicious h4:hover .permalink,
      #wrapperlicious dt:hover .permalink {
        display: block;
      }
    </style>
    <!-- Global site tag (gtag.js) - Google Analytics -->
    <script async src="https://www.googletagmanager.com/gtag/js?id=G-KVNWBNT5FB"></script>
    <script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());

      gtag('config', 'G-KVNWBNT5FB');
      gtag('config', 'UA-50555-3');
    </script>
  </head>
  <body>
    <nav class="navbar navbar-expand-md navbar-dark bg-dark justify-content-between">
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>
  <a class="navbar-brand" href="https://perldoc.perl.org/">Perldoc Browser</a>
  <div class="collapse navbar-collapse" id="navbarNav">
    <ul class="navbar-nav mr-auto">
      <li class="nav-item dropdown text-nowrap">
        <a class="nav-link dropdown-toggle" href="perlos2.html#" id="dropdownlink-stable" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">5.35.0</a>
        <div class="dropdown-menu" aria-labelledby="dropdownlink-stable">
          <a class="dropdown-item" href="https://perldoc.perl.org/perlos2">Latest</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.2/perlos2">5.38.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.1/perlos2">5.38.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.0/perlos2">5.38.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.3/perlos2">5.36.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.2/perlos2">5.36.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.1/perlos2">5.36.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.0/perlos2">5.36.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.3/perlos2">5.34.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.2/perlos2">5.34.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.1/perlos2">5.34.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.0/perlos2">5.34.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.32.1/perlos2">5.32.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.32.0/perlos2">5.32.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.3/perlos2">5.30.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.2/perlos2">5.30.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.1/perlos2">5.30.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.0/perlos2">5.30.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.3/perlos2">5.28.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.2/perlos2">5.28.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.1/perlos2">5.28.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.0/perlos2">5.28.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.3/perlos2">5.26.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.2/perlos2">5.26.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.1/perlos2">5.26.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.0/perlos2">5.26.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.4/perlos2">5.24.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.3/perlos2">5.24.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.2/perlos2">5.24.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.1/perlos2">5.24.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.0/perlos2">5.24.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.4/perlos2">5.22.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.3/perlos2">5.22.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.2/perlos2">5.22.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.1/perlos2">5.22.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.0/perlos2">5.22.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.3/perlos2">5.20.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.2/perlos2">5.20.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.1/perlos2">5.20.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.0/perlos2">5.20.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.4/perlos2">5.18.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.3/perlos2">5.18.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.2/perlos2">5.18.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.1/perlos2">5.18.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.0/perlos2">5.18.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.3/perlos2">5.16.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.2/perlos2">5.16.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.1/perlos2">5.16.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.0/perlos2">5.16.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.4/perlos2">5.14.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.3/perlos2">5.14.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.2/perlos2">5.14.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.1/perlos2">5.14.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.0/perlos2">5.14.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.5/perlos2">5.12.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.4/perlos2">5.12.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.3/perlos2">5.12.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.2/perlos2">5.12.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.1/perlos2">5.12.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.0/perlos2">5.12.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.10.1/perlos2">5.10.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.10.0/perlos2">5.10.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.9/perlos2">5.8.9</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.8/perlos2">5.8.8</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.7/perlos2">5.8.7</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.6/perlos2">5.8.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.5/perlos2">5.8.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.4/perlos2">5.8.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.3/perlos2">5.8.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.2/perlos2">5.8.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.1/perlos2">5.8.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.0/perlos2">5.8.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.6.2/perlos2">5.6.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.6.1/perlos2">5.6.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.6.0/perlos2">5.6.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_04/perlos2">5.005_04</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_03/perlos2">5.005_03</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_02/perlos2">5.005_02</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_01/perlos2">5.005_01</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005/perlos2">5.005</a>
        </div>
      </li>
      <li class="nav-item dropdown text-nowrap">
        <a class="nav-link dropdown-toggle" href="perlos2.html#" id="dropdownlink-dev" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Dev</a>
        <div class="dropdown-menu" aria-labelledby="dropdownlink-dev">
          <a class="dropdown-item" href="https://perldoc.perl.org/blead/perlos2">blead</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.6/perlos2">5.39.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.5/perlos2">5.39.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.4/perlos2">5.39.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.3/perlos2">5.39.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.2/perlos2">5.39.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.1/perlos2">5.39.1</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.0-RC2/perlos2">5.38.0-RC2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.0-RC1/perlos2">5.38.0-RC1</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.11/perlos2">5.37.11</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.10/perlos2">5.37.10</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.9/perlos2">5.37.9</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.8/perlos2">5.37.8</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.7/perlos2">5.37.7</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.6/perlos2">5.37.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.5/perlos2">5.37.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.4/perlos2">5.37.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.3/perlos2">5.37.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.2/perlos2">5.37.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.1/perlos2">5.37.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.0/perlos2">5.37.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.11/perlos2">5.35.11</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.10/perlos2">5.35.10</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.9/perlos2">5.35.9</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.8/perlos2">5.35.8</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.7/perlos2">5.35.7</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.6/perlos2">5.35.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.5/perlos2">5.35.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.4/perlos2">5.35.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.3/perlos2">5.35.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.2/perlos2">5.35.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.1/perlos2">5.35.1</a>
          <a class="dropdown-item active" href="perlos2.html">5.35.0</a>
        </div>
      </li>
      <li class="nav-item dropdown text-nowrap">
        <a class="nav-link dropdown-toggle" href="perlos2.html#" id="dropdownlink-nav" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Documentation</a>
        <div class="dropdown-menu" aria-labelledby="dropdownlink-nav">
          <a class="dropdown-item" href="perl.html">Perl</a>
          <a class="dropdown-item" href="perlintro.html">Intro</a>
          <a class="dropdown-item" href="perl.html#Tutorials">Tutorials</a>
          <a class="dropdown-item" href="perlfaq.html">FAQs</a>
          <a class="dropdown-item" href="perl.html#Reference-Manual">Reference</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="perlop.html">Operators</a>
          <a class="dropdown-item" href="functions.html">Functions</a>
          <a class="dropdown-item" href="variables.html">Variables</a>
          <a class="dropdown-item" href="modules.html">Modules</a>
          <a class="dropdown-item" href="perlutil.html">Utilities</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="perlcommunity.html">Community</a>
          <a class="dropdown-item" href="perlhist.html">History</a>
        </div>
      </li>
    </ul>
    <ul class="navbar-nav">
      <script>
        function set_expand (expand) {
          var perldocdiv = document.getElementById('perldocdiv');
          var width = window.getComputedStyle(perldocdiv).getPropertyValue('max-width');
          var expanded = (width == '' || width == 'none') ? true : false;
          if (expand === null) {
            expand = !expanded;
          }
          if ((expand && !expanded) || (!expand && expanded)) {
            perldocdiv.style.setProperty('max-width', expand ? 'none' : '960px');
            var button_classlist = document.getElementById('content-expand-button').classList;
            if (expand) {
              button_classlist.add('btn-light');
              button_classlist.remove('btn-outline-light');
            } else {
              button_classlist.add('btn-outline-light');
              button_classlist.remove('btn-light');
            }
          }
          return expand;
        }
        function toggle_expand () {
          var expand = set_expand(null);
          document.cookie = 'perldoc_expand=' + (expand ? 1 : 0) + '; path=/; expires=Tue, 19 Jan 2038 03:14:07 UTC';
        }
        function read_expand () {
          return document.cookie.split(';').some(function (item) { return item.indexOf('perldoc_expand=1') >= 0 });
        }
        if (document.readyState === 'loading') {
          document.addEventListener('DOMContentLoaded', function () {
            if (read_expand()) {
              set_expand(true);
            }
          });
        } else if (read_expand()) {
          set_expand(true);
        }
      </script>
      <button id="content-expand-button" type="button" class="btn btn-outline-light d-none d-lg-inline-block mr-2" onclick="toggle_expand()">Expand</button>
    <ul>
    <form class="form-inline" method="get" action="https://perldoc.perl.org/5.35.0/search">
      <input class="form-control mr-3" type="search" name="q" placeholder="Search" aria-label="Search">
    </form>
  </div>
</nav>

    <div id="wrapperlicious" class="container-fluid">
      <div id="perldocdiv">
        <div id="links">
          <a href="perlos2.html">perlos2</a>
          <div id="more">
            (<a href="perlos2.txt">source</a>,
            <a href="https://metacpan.org/pod/perlos2">CPAN</a>)
          </div>
        </div>
        <div class="leading-notice">
          You are viewing the version of this documentation from Perl 5.35.0.
            This is a development version of Perl.
        </div>
        <h1><a id="toc">CONTENTS</a></h1>
                  <ul>
              <li>
                <a class="text-decoration-none" href="perlos2.html#NAME">NAME</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#SYNOPSIS">SYNOPSIS</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#DESCRIPTION">DESCRIPTION</a>
                            <ul>
              <li>
                <a class="text-decoration-none" href="perlos2.html#Target">Target</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#Other-OSes">Other OSes</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#Prerequisites">Prerequisites</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#Starting-Perl-programs-under-OS/2-(and-DOS-and...)">Starting Perl programs under OS/2 (and DOS and...)</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#Starting-OS/2-(and-DOS)-programs-under-Perl">Starting OS/2 (and DOS) programs under Perl</a>
              </li>
          </ul>

              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#Frequently-asked-questions">Frequently asked questions</a>
                            <ul>
              <li>
                <a class="text-decoration-none" href="perlos2.html#%22It-does-not-work%22">&quot;It does not work&quot;</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#I-cannot-run-external-programs">I cannot run external programs</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#I-cannot-embed-perl-into-my-program,-or-use-perl.dll-from-my-program.">I cannot embed perl into my program, or use perl.dll from my program.</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#%60%60-and-pipe-open-do-not-work-under-DOS.">`` and pipe-open do not work under DOS.</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#Cannot-start-find.exe-%22pattern%22-file">Cannot start find.exe &quot;pattern&quot; file</a>
              </li>
          </ul>

              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#INSTALLATION">INSTALLATION</a>
                            <ul>
              <li>
                <a class="text-decoration-none" href="perlos2.html#Automatic-binary-installation">Automatic binary installation</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#Manual-binary-installation">Manual binary installation</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#Warning">Warning</a>
              </li>
          </ul>

              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#Accessing-documentation">Accessing documentation</a>
                            <ul>
              <li>
                <a class="text-decoration-none" href="perlos2.html#OS/2-.INF-file">OS/2 .INF file</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#Plain-text">Plain text</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#Manpages">Manpages</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#HTML">HTML</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#GNU-info-files">GNU info files</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#PDF-files">PDF files</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#LaTeX-docs">LaTeX docs</a>
              </li>
          </ul>

              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#BUILD">BUILD</a>
                            <ul>
              <li>
                <a class="text-decoration-none" href="perlos2.html#The-short-story">The short story</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#Prerequisites1">Prerequisites</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#Getting-perl-source">Getting perl source</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#Application-of-the-patches">Application of the patches</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#Hand-editing">Hand-editing</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#Making">Making</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#Testing">Testing</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#Installing-the-built-perl">Installing the built perl</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#a.out-style-build">a.out-style build</a>
              </li>
          </ul>

              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#Building-a-binary-distribution">Building a binary distribution</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#Building-custom-.EXE-files">Building custom .EXE files</a>
                            <ul>
              <li>
                <a class="text-decoration-none" href="perlos2.html#Making-executables-with-a-custom-collection-of-statically-loaded-extensions">Making executables with a custom collection of statically loaded extensions</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#Making-executables-with-a-custom-search-paths">Making executables with a custom search-paths</a>
              </li>
          </ul>

              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#Build-FAQ">Build FAQ</a>
                            <ul>
              <li>
                <a class="text-decoration-none" href="perlos2.html#Some-/-became-%5C-in-pdksh.">Some / became \ in pdksh.</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#&#39;errno&#39;-unresolved-external">&#39;errno&#39; - unresolved external</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#Problems-with-tr-or-sed">Problems with tr or sed</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#Some-problem-(forget-which-;-)">Some problem (forget which ;-)</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#Library-...-not-found">Library ... not found</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#Segfault-in-make">Segfault in make</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#op/sprintf-test-failure">op/sprintf test failure</a>
              </li>
          </ul>

              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#Specific-(mis)features-of-OS/2-port">Specific (mis)features of OS/2 port</a>
                            <ul>
              <li>
                <a class="text-decoration-none" href="perlos2.html#setpriority,-getpriority">setpriority, getpriority</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#system()">system()</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#extproc-on-the-first-line">extproc on the first line</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#Additional-modules:">Additional modules:</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#Prebuilt-methods:">Prebuilt methods:</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#Prebuilt-variables:">Prebuilt variables:</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#Misfeatures">Misfeatures</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#Modifications">Modifications</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#Identifying-DLLs">Identifying DLLs</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#Centralized-management-of-resources">Centralized management of resources</a>
              </li>
          </ul>

              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#Perl-flavors">Perl flavors</a>
                            <ul>
              <li>
                <a class="text-decoration-none" href="perlos2.html#perl.exe">perl.exe</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#perl_.exe">perl_.exe</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#perl__.exe">perl__.exe</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#perl___.exe">perl___.exe</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#Why-strange-names?">Why strange names?</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#Why-dynamic-linking?">Why dynamic linking?</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#Why-chimera-build?">Why chimera build?</a>
              </li>
          </ul>

              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#ENVIRONMENT">ENVIRONMENT</a>
                            <ul>
              <li>
                <a class="text-decoration-none" href="perlos2.html#PERLLIB_PREFIX">PERLLIB_PREFIX</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#PERL_BADLANG1">PERL_BADLANG</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#PERL_BADFREE1">PERL_BADFREE</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#PERL_SH_DIR">PERL_SH_DIR</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#USE_PERL_FLOCK">USE_PERL_FLOCK</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#TMP-or-TEMP">TMP or TEMP</a>
              </li>
          </ul>

              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#Evolution">Evolution</a>
                            <ul>
              <li>
                <a class="text-decoration-none" href="perlos2.html#Text-mode-filehandles">Text-mode filehandles</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#Priorities">Priorities</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#DLL-name-mangling:-pre-5.6.2">DLL name mangling: pre 5.6.2</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#DLL-name-mangling:-5.6.2-and-beyond">DLL name mangling: 5.6.2 and beyond</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#DLL-forwarder-generation">DLL forwarder generation</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#Threading">Threading</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#Calls-to-external-programs">Calls to external programs</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#Memory-allocation">Memory allocation</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#Threads">Threads</a>
              </li>
          </ul>

              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#BUGS">BUGS</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#AUTHOR">AUTHOR</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlos2.html#SEE-ALSO">SEE ALSO</a>
              </li>
          </ul>

      <h1 id="NAME"><a class="permalink" href="perlos2.html#NAME">#</a>NAME</h1>

<p>perlos2 - Perl under OS/2, DOS, Win0.3*, Win0.95 and WinNT.</p>

<h1 id="SYNOPSIS"><a class="permalink" href="perlos2.html#SYNOPSIS">#</a>SYNOPSIS</h1>

<p>One can read this document in the following formats:</p>

<pre><code class="plaintext">man perlos2
view perl perlos2
explorer perlos2.html
info perlos2</code></pre>

<p>to list some (not all may be available simultaneously), or it may be read <i>as is</i>: either as <i>README.os2</i>, or <i>pod/perlos2.pod</i>.</p>

<p>To read the <i>.INF</i> version of documentation (<b>very</b> recommended) outside of OS/2, one needs an IBM&#39;s reader (may be available on IBM ftp sites (?) (URL anyone?)) or shipped with PC DOS 7.0 and IBM&#39;s Visual Age C++ 3.5.</p>

<p>A copy of a Win* viewer is contained in the &quot;Just add OS/2 Warp&quot; package</p>

<pre><code class="plaintext">ftp://ftp.software.ibm.com/ps/products/os2/tools/jaow/jaow.zip</code></pre>

<p>in <i>?:\JUST_ADD\view.exe</i>. This gives one an access to EMX&#39;s <i>.INF</i> docs as well (text form is available in <i>/emx/doc</i> in EMX&#39;s distribution). There is also a different viewer named xview.</p>

<p>Note that if you have <i>lynx.exe</i> or <i>netscape.exe</i> installed, you can follow WWW links from this document in <i>.INF</i> format. If you have EMX docs installed correctly, you can follow library links (you need to have <code>view emxbook</code> working by setting <code>EMXBOOK</code> environment variable as it is described in EMX docs).</p>

<h1 id="DESCRIPTION"><a class="permalink" href="perlos2.html#DESCRIPTION">#</a>DESCRIPTION</h1>

<h2 id="Target"><a class="permalink" href="perlos2.html#Target">#</a>Target</h2>

<p>The target is to make OS/2 one of the best supported platform for using/building/developing Perl and <i>Perl applications</i>, as well as make Perl the best language to use under OS/2. The secondary target is to try to make this work under DOS and Win* as well (but not <b>too</b> hard).</p>

<p>The current state is quite close to this target. Known limitations:</p>

<ul>

<li><p>Some *nix programs use fork() a lot; with the mostly useful flavors of perl for OS/2 (there are several built simultaneously) this is supported; but some flavors do not support this (e.g., when Perl is called from inside REXX). Using fork() after <i>use</i>ing dynamically loading extensions would not work with <i>very</i> old versions of EMX.</p>

</li>
<li><p>You need a separate perl executable <i>perl__.exe</i> (see <a href="perlos2.html#perl__.exe">&quot;perl__.exe&quot;</a>) if you want to use PM code in your application (as Perl/Tk or OpenGL Perl modules do) without having a text-mode window present.</p>

<p>While using the standard <i>perl.exe</i> from a text-mode window is possible too, I have seen cases when this causes degradation of the system stability. Using <i>perl__.exe</i> avoids such a degradation.</p>

</li>
<li><p>There is no simple way to access WPS objects. The only way I know is via <code>OS2::REXX</code> and <code>SOM</code> extensions (see <a href="./OS2::REXX.html">OS2::REXX</a>, <a href="SOM.html">SOM</a>). However, we do not have access to convenience methods of Object-REXX. (Is it possible at all? I know of no Object-REXX API.) The <code>SOM</code> extension (currently in alpha-text) may eventually remove this shortcoming; however, due to the fact that DII is not supported by the <code>SOM</code> module, using <code>SOM</code> is not as convenient as one would like it.</p>

</li>
</ul>

<p>Please keep this list up-to-date by informing me about other items.</p>

<h2 id="Other-OSes"><a class="permalink" href="perlos2.html#Other-OSes">#</a><a id="Other"></a>Other OSes</h2>

<p>Since OS/2 port of perl uses a remarkable EMX environment, it can run (and build extensions, and - possibly - be built itself) under any environment which can run EMX. The current list is DOS, DOS-inside-OS/2, Win0.3*, Win0.95 and WinNT. Out of many perl flavors, only one works, see <a href="perlos2.html#perl_.exe">&quot;<i>perl_.exe</i>&quot;</a>.</p>

<p>Note that not all features of Perl are available under these environments. This depends on the features the <i>extender</i> - most probably RSX - decided to implement.</p>

<p>Cf. <a href="perlos2.html#Prerequisites">&quot;Prerequisites&quot;</a>.</p>

<h2 id="Prerequisites"><a class="permalink" href="perlos2.html#Prerequisites">#</a>Prerequisites</h2>

<dl>

<dt id="EMX"><a class="permalink" href="perlos2.html#EMX">#</a>EMX</dt>
<dd>

<p>EMX runtime is required (may be substituted by RSX). Note that it is possible to make <i>perl_.exe</i> to run under DOS without any external support by binding <i>emx.exe</i>/<i>rsx.exe</i> to it, see <code>emxbind</code>. Note that under DOS for best results one should use RSX runtime, which has much more functions working (like <code>fork</code>, <code>popen</code> and so on). In fact RSX is required if there is no VCPI present. Note the RSX requires DPMI. Many implementations of DPMI are known to be very buggy, beware!</p>

<p>Only the latest runtime is supported, currently <code>0.9d fix 03</code>. Perl may run under earlier versions of EMX, but this is not tested.</p>

<p>One can get different parts of EMX from, say</p>

<pre><code class="plaintext">ftp://crydee.sai.msu.ru/pub/comp/os/os2/leo/gnu/emx+gcc/
http://hobbes.nmsu.edu/h-browse.php?dir=/pub/os2/dev/emx/v0.9d/</code></pre>

<p>The runtime component should have the name <i>emxrt.zip</i>.</p>

<p><b>NOTE</b>. When using <i>emx.exe</i>/<i>rsx.exe</i>, it is enough to have them on your path. One does not need to specify them explicitly (though this</p>

<pre><code class="plaintext">emx perl_.exe -de 0</code></pre>

<p>will work as well.)</p>

</dd>
<dt id="RSX"><a class="permalink" href="perlos2.html#RSX">#</a>RSX</dt>
<dd>

<p>To run Perl on DPMI platforms one needs RSX runtime. This is needed under DOS-inside-OS/2, Win0.3*, Win0.95 and WinNT (see <a href="perlos2.html#Other-OSes">&quot;Other OSes&quot;</a>). RSX would not work with VCPI only, as EMX would, it requires DMPI.</p>

<p>Having RSX and the latest <i>sh.exe</i> one gets a fully functional <b>*nix</b>-ish environment under DOS, say, <code>fork</code>, <code>``</code> and pipe-<code>open</code> work. In fact, MakeMaker works (for static build), so one can have Perl development environment under DOS.</p>

<p>One can get RSX from, say</p>

<pre><code class="plaintext">http://cd.textfiles.com/hobbesos29804/disk1/EMX09C/
ftp://crydee.sai.msu.ru/pub/comp/os/os2/leo/gnu/emx+gcc/contrib/</code></pre>

<p>Contact the author on <code>rainer@mathematik.uni-bielefeld.de</code>.</p>

<p>The latest <i>sh.exe</i> with DOS hooks is available in</p>

<pre><code class="plaintext">http://www.ilyaz.org/software/os2/</code></pre>

<p>as <i>sh_dos.zip</i> or under similar names starting with <code>sh</code>, <code>pdksh</code> etc.</p>

</dd>
<dt id="HPFS"><a class="permalink" href="perlos2.html#HPFS">#</a>HPFS</dt>
<dd>

<p>Perl does not care about file systems, but the perl library contains many files with long names, so to install it intact one needs a file system which supports long file names.</p>

<p>Note that if you do not plan to build the perl itself, it may be possible to fool EMX to truncate file names. This is not supported, read EMX docs to see how to do it.</p>

</dd>
<dt id="pdksh"><a class="permalink" href="perlos2.html#pdksh">#</a>pdksh</dt>
<dd>

<p>To start external programs with complicated command lines (like with pipes in between, and/or quoting of arguments), Perl uses an external shell. With EMX port such shell should be named <i>sh.exe</i>, and located either in the wired-in-during-compile locations (usually <i>F:/bin</i>), or in configurable location (see <a href="perlos2.html#PERL_SH_DIR">&quot;<code>PERL_SH_DIR</code>&quot;</a>).</p>

<p>For best results use EMX pdksh. The standard binary (5.2.14 or later) runs under DOS (with <a href="perlos2.html#RSX">&quot;RSX&quot;</a>) as well, see</p>

<pre><code class="plaintext">http://www.ilyaz.org/software/os2/</code></pre>

</dd>
</dl>

<h2 id="Starting-Perl-programs-under-OS/2-(and-DOS-and...)"><a class="permalink" href="perlos2.html#Starting-Perl-programs-under-OS/2-(and-DOS-and...)">#</a><a id="Starting"></a><a id="Starting-Perl-programs-under-OS-2-and-DOS-and"></a>Starting Perl programs under OS/2 (and DOS and...)</h2>

<p>Start your Perl program <i>foo.pl</i> with arguments <code>arg1 arg2 arg3</code> the same way as on any other platform, by</p>

<pre><code class="plaintext">perl foo.pl arg1 arg2 arg3</code></pre>

<p>If you want to specify perl options <code>-my_opts</code> to the perl itself (as opposed to your program), use</p>

<pre><code class="plaintext">perl -my_opts foo.pl arg1 arg2 arg3</code></pre>

<p>Alternately, if you use OS/2-ish shell, like CMD or 4os2, put the following at the start of your perl script:</p>

<pre><code class="plaintext">extproc perl -S -my_opts</code></pre>

<p>rename your program to <i>foo.cmd</i>, and start it by typing</p>

<pre><code class="plaintext">foo arg1 arg2 arg3</code></pre>

<p>Note that because of stupid OS/2 limitations the full path of the perl script is not available when you use <code>extproc</code>, thus you are forced to use <code>-S</code> perl switch, and your script should be on the <code>PATH</code>. As a plus side, if you know a full path to your script, you may still start it with</p>

<pre><code class="plaintext">perl ../../blah/foo.cmd arg1 arg2 arg3</code></pre>

<p>(note that the argument <code>-my_opts</code> is taken care of by the <code>extproc</code> line in your script, see <code><a href="perlos2.html#extproc">&quot;extproc&quot;</a> on the first line</code>).</p>

<p>To understand what the above <i>magic</i> does, read perl docs about <code>-S</code> switch - see <a href="perlrun.html">perlrun</a>, and cmdref about <code>extproc</code>:</p>

<pre><code class="plaintext">view perl perlrun
man perlrun
view cmdref extproc
help extproc</code></pre>

<p>or whatever method you prefer.</p>

<p>There are also endless possibilities to use <i>executable extensions</i> of 4os2, <i>associations</i> of WPS and so on... However, if you use *nixish shell (like <i>sh.exe</i> supplied in the binary distribution), you need to follow the syntax specified in <a href="perlrun.html#Command-Switches">&quot;Command Switches&quot; in perlrun</a>.</p>

<p>Note that <b>-S</b> switch supports scripts with additional extensions <i>.cmd</i>, <i>.btm</i>, <i>.bat</i>, <i>.pl</i> as well.</p>

<h2 id="Starting-OS/2-(and-DOS)-programs-under-Perl"><a class="permalink" href="perlos2.html#Starting-OS/2-(and-DOS)-programs-under-Perl">#</a><a id="Starting1"></a><a id="Starting-OS-2-and-DOS-programs-under-Perl"></a>Starting OS/2 (and DOS) programs under Perl</h2>

<p>This is what system() (see <a href="perlfunc.html#system">&quot;system&quot; in perlfunc</a>), <code>``</code> (see <a href="perlop.html#I%2FO-Operators">&quot;I/O Operators&quot; in perlop</a>), and <i>open pipe</i> (see <a href="perlfunc.html#open">&quot;open&quot; in perlfunc</a>) are for. (Avoid exec() (see <a href="perlfunc.html#exec">&quot;exec&quot; in perlfunc</a>) unless you know what you do).</p>

<p>Note however that to use some of these operators you need to have a sh-syntax shell installed (see <a href="perlos2.html#Pdksh">&quot;Pdksh&quot;</a>, <a href="perlos2.html#Frequently-asked-questions">&quot;Frequently asked questions&quot;</a>), and perl should be able to find it (see <a href="perlos2.html#PERL_SH_DIR">&quot;<code>PERL_SH_DIR</code>&quot;</a>).</p>

<p>The cases when the shell is used are:</p>

<ol>

<li><p>One-argument system() (see <a href="perlfunc.html#system">&quot;system&quot; in perlfunc</a>), exec() (see <a href="perlfunc.html#exec">&quot;exec&quot; in perlfunc</a>) with redirection or shell meta-characters;</p>

</li>
<li><p>Pipe-open (see <a href="perlfunc.html#open">&quot;open&quot; in perlfunc</a>) with the command which contains redirection or shell meta-characters;</p>

</li>
<li><p>Backticks <code>``</code> (see <a href="perlop.html#I%2FO-Operators">&quot;I/O Operators&quot; in perlop</a>) with the command which contains redirection or shell meta-characters;</p>

</li>
<li><p>If the executable called by system()/exec()/pipe-open()/<code>``</code> is a script with the &quot;magic&quot; <code>#!</code> line or <code>extproc</code> line which specifies shell;</p>

</li>
<li><p>If the executable called by system()/exec()/pipe-open()/<code>``</code> is a script without &quot;magic&quot; line, and <code>$ENV{EXECSHELL}</code> is set to shell;</p>

</li>
<li><p>If the executable called by system()/exec()/pipe-open()/<code>``</code> is not found (is not this remark obsolete?);</p>

</li>
<li><p>For globbing (see <a href="perlfunc.html#glob">&quot;glob&quot; in perlfunc</a>, <a href="perlop.html#I%2FO-Operators">&quot;I/O Operators&quot; in perlop</a>) (obsolete? Perl uses builtin globbing nowadays...).</p>

</li>
</ol>

<p>For the sake of speed for a common case, in the above algorithms backslashes in the command name are not considered as shell metacharacters.</p>

<p>Perl starts scripts which begin with cookies <code>extproc</code> or <code>#!</code> directly, without an intervention of shell. Perl uses the same algorithm to find the executable as <i>pdksh</i>: if the path on <code>#!</code> line does not work, and contains <code>/</code>, then the directory part of the executable is ignored, and the executable is searched in <i>.</i> and on <code>PATH</code>. To find arguments for these scripts Perl uses a different algorithm than <i>pdksh</i>: up to 3 arguments are recognized, and trailing whitespace is stripped.</p>

<p>If a script does not contain such a cooky, then to avoid calling <i>sh.exe</i>, Perl uses the same algorithm as <i>pdksh</i>: if <code>$ENV{EXECSHELL}</code> is set, the script is given as the first argument to this command, if not set, then <code>$ENV{COMSPEC} /c</code> is used (or a hardwired guess if <code>$ENV{COMSPEC}</code> is not set).</p>

<p>When starting scripts directly, Perl uses exactly the same algorithm as for the search of script given by <b>-S</b> command-line option: it will look in the current directory, then on components of <code>$ENV{PATH}</code> using the following order of appended extensions: no extension, <i>.cmd</i>, <i>.btm</i>, <i>.bat</i>, <i>.pl</i>.</p>

<p>Note that Perl will start to look for scripts only if OS/2 cannot start the specified application, thus <code>system &#39;blah&#39;</code> will not look for a script if there is an executable file <i>blah.exe</i> <i>anywhere</i> on <code>PATH</code>. In other words, <code>PATH</code> is essentially searched twice: once by the OS for an executable, then by Perl for scripts.</p>

<p>Note also that executable files on OS/2 can have an arbitrary extension, but <i>.exe</i> will be automatically appended if no dot is present in the name. The workaround is as simple as that: since <i>blah.</i> and <i>blah</i> denote the same file (at list on FAT and HPFS file systems), to start an executable residing in file <i>n:/bin/blah</i> (no extension) give an argument <code>n:/bin/blah.</code> (dot appended) to system().</p>

<p>Perl will start PM programs from VIO (=text-mode) Perl process in a separate PM session; the opposite is not true: when you start a non-PM program from a PM Perl process, Perl would not run it in a separate session. If a separate session is desired, either ensure that shell will be used, as in <code>system &#39;cmd /c myprog&#39;</code>, or start it using optional arguments to system() documented in <code>OS2::Process</code> module. This is considered to be a feature.</p>

<h1 id="Frequently-asked-questions"><a class="permalink" href="perlos2.html#Frequently-asked-questions">#</a><a id="Frequently"></a>Frequently asked questions</h1>

<h2 id="&quot;It-does-not-work&quot;"><a class="permalink" href="perlos2.html#%22It-does-not-work%22">#</a><a id="It-does-not-work"></a>&quot;It does not work&quot;</h2>

<p>Perl binary distributions come with a <i>testperl.cmd</i> script which tries to detect common problems with misconfigured installations. There is a pretty large chance it will discover which step of the installation you managed to goof. <code>;-)</code></p>

<h2 id="I-cannot-run-external-programs"><a class="permalink" href="perlos2.html#I-cannot-run-external-programs">#</a><a id="I"></a>I cannot run external programs</h2>

<ul>

<li><p>Did you run your programs with <code>-w</code> switch? See <a href="perlos2.html#Starting-OS%2F2-%28and-DOS%29-programs-under-Perl">&quot;Starting OS/2 (and DOS) programs under Perl&quot;</a>.</p>

</li>
<li><p>Do you try to run <i>internal</i> shell commands, like <code>`copy a b`</code> (internal for <i>cmd.exe</i>), or <code>`glob a*b`</code> (internal for ksh)? You need to specify your shell explicitly, like <code>`cmd /c copy a b`</code>, since Perl cannot deduce which commands are internal to your shell.</p>

</li>
</ul>

<h2 id="I-cannot-embed-perl-into-my-program,-or-use-perl.dll-from-my-program."><a class="permalink" href="perlos2.html#I-cannot-embed-perl-into-my-program,-or-use-perl.dll-from-my-program.">#</a><a id="I1"></a><a id="I-cannot-embed-perl-into-my-program-or-use-perl.dll-from-my-program"></a>I cannot embed perl into my program, or use <i>perl.dll</i> from my program.</h2>

<dl>

<dt id="Is-your-program-EMX-compiled-with-Zmt-Zcrtdll?"><a class="permalink" href="perlos2.html#Is-your-program-EMX-compiled-with-Zmt-Zcrtdll?">#</a><a id="Is"></a><a id="Is-your-program-EMX-compiled-with--Zmt--Zcrtdll"></a>Is your program EMX-compiled with <code>-Zmt -Zcrtdll</code>?</dt>
<dd>

<p>Well, nowadays Perl DLL should be usable from a differently compiled program too... If you can run Perl code from REXX scripts (see <a href="./OS2::REXX.html">OS2::REXX</a>), then there are some other aspect of interaction which are overlooked by the current hackish code to support differently-compiled principal programs.</p>

<p>If everything else fails, you need to build a stand-alone DLL for perl. Contact me, I did it once. Sockets would not work, as a lot of other stuff.</p>

</dd>
<dt id="Did-you-use-ExtUtils::Embed?"><a class="permalink" href="perlos2.html#Did-you-use-ExtUtils::Embed?">#</a><a id="Did"></a><a id="Did-you-use-ExtUtils::Embed"></a>Did you use <a href="./ExtUtils::Embed.html">ExtUtils::Embed</a>?</dt>
<dd>

<p>Some time ago I had reports it does not work. Nowadays it is checked in the Perl test suite, so grep <i>./t</i> subdirectory of the build tree (as well as <i>*.t</i> files in the <i>./lib</i> subdirectory) to find how it should be done &quot;correctly&quot;.</p>

</dd>
</dl>

<h2 id="``-and-pipe-open-do-not-work-under-DOS."><a class="permalink" href="perlos2.html#%60%60-and-pipe-open-do-not-work-under-DOS.">#</a><a id="and-pipe-open-do-not-work-under-DOS"></a><code>``</code> and pipe-<code>open</code> do not work under DOS.</h2>

<p>This may a variant of just <a href="perlos2.html#I-cannot-run-external-programs">&quot;I cannot run external programs&quot;</a>, or a deeper problem. Basically: you <i>need</i> RSX (see <a href="perlos2.html#Prerequisites">&quot;Prerequisites&quot;</a>) for these commands to work, and you may need a port of <i>sh.exe</i> which understands command arguments. One of such ports is listed in <a href="perlos2.html#Prerequisites">&quot;Prerequisites&quot;</a> under RSX. Do not forget to set variable <a href="perlos2.html#PERL_SH_DIR">&quot;<code>PERL_SH_DIR</code>&quot;</a> as well.</p>

<p>DPMI is required for RSX.</p>

<h2 id="Cannot-start-find.exe-&quot;pattern&quot;-file"><a class="permalink" href="perlos2.html#Cannot-start-find.exe-%22pattern%22-file">#</a><a id="Cannot"></a><a id="Cannot-start-find.exe-pattern-file"></a>Cannot start <code>find.exe &quot;pattern&quot; file</code></h2>

<p>The whole idea of the &quot;standard C API to start applications&quot; is that the forms <code>foo</code> and <code>&quot;foo&quot;</code> of program arguments are completely interchangeable. <i>find</i> breaks this paradigm;</p>

<pre><code class="plaintext">find &quot;pattern&quot; file
find pattern file</code></pre>

<p>are not equivalent; <i>find</i> cannot be started directly using the above API. One needs a way to surround the doublequotes in some other quoting construction, necessarily having an extra non-Unixish shell in between.</p>

<p>Use one of</p>

<pre><code>system &#39;cmd&#39;, &#39;/c&#39;, &#39;find &quot;pattern&quot; file&#39;;
`cmd /c &#39;find &quot;pattern&quot; file&#39;`</code></pre>

<p>This would start <i>find.exe</i> via <i>cmd.exe</i> via <code>sh.exe</code> via <code>perl.exe</code>, but this is a price to pay if you want to use non-conforming program.</p>

<h1 id="INSTALLATION"><a class="permalink" href="perlos2.html#INSTALLATION">#</a>INSTALLATION</h1>

<h2 id="Automatic-binary-installation"><a class="permalink" href="perlos2.html#Automatic-binary-installation">#</a><a id="Automatic"></a>Automatic binary installation</h2>

<p>The most convenient way of installing a binary distribution of perl is via perl installer <i>install.exe</i>. Just follow the instructions, and 99% of the installation blues would go away.</p>

<p>Note however, that you need to have <i>unzip.exe</i> on your path, and EMX environment <i>running</i>. The latter means that if you just installed EMX, and made all the needed changes to <i>Config.sys</i>, you may need to reboot in between. Check EMX runtime by running</p>

<pre><code class="plaintext">emxrev</code></pre>

<p>Binary installer also creates a folder on your desktop with some useful objects. If you need to change some aspects of the work of the binary installer, feel free to edit the file <i>Perl.pkg</i>. This may be useful e.g., if you need to run the installer many times and do not want to make many interactive changes in the GUI.</p>

<p><b>Things not taken care of by automatic binary installation:</b></p>

<dl>

<dt id="PERL_BADLANG"><a class="permalink" href="perlos2.html#PERL_BADLANG">#</a><code>PERL_BADLANG</code></dt>
<dd>

<p>may be needed if you change your codepage <i>after</i> perl installation, and the new value is not supported by EMX. See <a href="perlos2.html#PERL_BADLANG">&quot;<code>PERL_BADLANG</code>&quot;</a>.</p>

</dd>
<dt id="PERL_BADFREE"><a class="permalink" href="perlos2.html#PERL_BADFREE">#</a><code>PERL_BADFREE</code></dt>
<dd>

<p>see <a href="perlos2.html#PERL_BADFREE">&quot;<code>PERL_BADFREE</code>&quot;</a>.</p>

</dd>
<dt id="Config.pm"><a class="permalink" href="perlos2.html#Config.pm">#</a><a id="Config"></a><i>Config.pm</i></dt>
<dd>

<p>This file resides somewhere deep in the location you installed your perl library, find it out by</p>

<pre><code>perl -MConfig -le &quot;print $INC{&#39;Config.pm&#39;}&quot;</code></pre>

<p>While most important values in this file <i>are</i> updated by the binary installer, some of them may need to be hand-edited. I know no such data, please keep me informed if you find one. Moreover, manual changes to the installed version may need to be accompanied by an edit of this file.</p>

</dd>
</dl>

<p><b>NOTE</b>. Because of a typo the binary installer of 5.00305 would install a variable <code>PERL_SHPATH</code> into <i>Config.sys</i>. Please remove this variable and put <code><a href="perlos2.html#PERL_SH_DIR">&quot;PERL_SH_DIR&quot;</a></code> instead.</p>

<h2 id="Manual-binary-installation"><a class="permalink" href="perlos2.html#Manual-binary-installation">#</a><a id="Manual"></a>Manual binary installation</h2>

<p>As of version 5.00305, OS/2 perl binary distribution comes split into 11 components. Unfortunately, to enable configurable binary installation, the file paths in the zip files are not absolute, but relative to some directory.</p>

<p>Note that the extraction with the stored paths is still necessary (default with unzip, specify <code>-d</code> to pkunzip). However, you need to know where to extract the files. You need also to manually change entries in <i>Config.sys</i> to reflect where did you put the files. Note that if you have some primitive unzipper (like <code>pkunzip</code>), you may get a lot of warnings/errors during unzipping. Upgrade to <code>(w)unzip</code>.</p>

<p>Below is the sample of what to do to reproduce the configuration on my machine. In <i>VIEW.EXE</i> you can press <code>Ctrl-Insert</code> now, and cut-and-paste from the resulting file - created in the directory you started <i>VIEW.EXE</i> from.</p>

<p>For each component, we mention environment variables related to each installation directory. Either choose directories to match your values of the variables, or create/append-to variables to take into account the directories.</p>

<dl>

<dt id="Perl-VIO-and-PM-executables-(dynamically-linked)"><a class="permalink" href="perlos2.html#Perl-VIO-and-PM-executables-(dynamically-linked)">#</a><a id="Perl"></a><a id="Perl-VIO-and-PM-executables-dynamically-linked"></a>Perl VIO and PM executables (dynamically linked)</dt>
<dd>

<pre><code class="plaintext">unzip perl_exc.zip *.exe *.ico -d f:/emx.add/bin
unzip perl_exc.zip *.dll -d f:/emx.add/dll</code></pre>

<p>(have the directories with <code>*.exe</code> on PATH, and <code>*.dll</code> on LIBPATH);</p>

</dd>
<dt id="Perl_-VIO-executable-(statically-linked)"><a class="permalink" href="perlos2.html#Perl_-VIO-executable-(statically-linked)">#</a><a id="Perl_"></a><a id="Perl_-VIO-executable-statically-linked"></a>Perl_ VIO executable (statically linked)</dt>
<dd>

<pre><code class="plaintext">unzip perl_aou.zip -d f:/emx.add/bin</code></pre>

<p>(have the directory on PATH);</p>

</dd>
<dt id="Executables-for-Perl-utilities"><a class="permalink" href="perlos2.html#Executables-for-Perl-utilities">#</a><a id="Executables"></a>Executables for Perl utilities</dt>
<dd>

<pre><code class="plaintext">unzip perl_utl.zip -d f:/emx.add/bin</code></pre>

<p>(have the directory on PATH);</p>

</dd>
<dt id="Main-Perl-library"><a class="permalink" href="perlos2.html#Main-Perl-library">#</a><a id="Main"></a>Main Perl library</dt>
<dd>

<pre><code class="plaintext">unzip perl_mlb.zip -d f:/perllib/lib</code></pre>

<p>If this directory is exactly the same as the prefix which was compiled into <i>perl.exe</i>, you do not need to change anything. However, for perl to find the library if you use a different path, you need to <code>set PERLLIB_PREFIX</code> in <i>Config.sys</i>, see <a href="perlos2.html#PERLLIB_PREFIX">&quot;<code>PERLLIB_PREFIX</code>&quot;</a>.</p>

</dd>
<dt id="Additional-Perl-modules"><a class="permalink" href="perlos2.html#Additional-Perl-modules">#</a><a id="Additional"></a>Additional Perl modules</dt>
<dd>

<pre><code class="plaintext">unzip perl_ste.zip -d f:/perllib/lib/site_perl/5.35.0/</code></pre>

<p>Same remark as above applies. Additionally, if this directory is not one of directories on @INC (and @INC is influenced by <code>PERLLIB_PREFIX</code>), you need to put this directory and subdirectory <i>./os2</i> in <code>PERLLIB</code> or <code>PERL5LIB</code> variable. Do not use <code>PERL5LIB</code> unless you have it set already. See <a href="perl.html#ENVIRONMENT">&quot;ENVIRONMENT&quot; in perl</a>.</p>

<p><b>[Check whether this extraction directory is still applicable with the new directory structure layout!]</b></p>

</dd>
<dt id="Tools-to-compile-Perl-modules"><a class="permalink" href="perlos2.html#Tools-to-compile-Perl-modules">#</a><a id="Tools"></a>Tools to compile Perl modules</dt>
<dd>

<pre><code class="plaintext">unzip perl_blb.zip -d f:/perllib/lib</code></pre>

<p>Same remark as for <i>perl_ste.zip</i>.</p>

</dd>
<dt id="Manpages-for-Perl-and-utilities"><a class="permalink" href="perlos2.html#Manpages-for-Perl-and-utilities">#</a><a id="Manpages1"></a>Manpages for Perl and utilities</dt>
<dd>

<pre><code class="plaintext">unzip perl_man.zip -d f:/perllib/man</code></pre>

<p>This directory should better be on <code>MANPATH</code>. You need to have a working <i>man</i> to access these files.</p>

</dd>
<dt id="Manpages-for-Perl-modules"><a class="permalink" href="perlos2.html#Manpages-for-Perl-modules">#</a><a id="Manpages2"></a>Manpages for Perl modules</dt>
<dd>

<pre><code class="plaintext">unzip perl_mam.zip -d f:/perllib/man</code></pre>

<p>This directory should better be on <code>MANPATH</code>. You need to have a working man to access these files.</p>

</dd>
<dt id="Source-for-Perl-documentation"><a class="permalink" href="perlos2.html#Source-for-Perl-documentation">#</a><a id="Source"></a>Source for Perl documentation</dt>
<dd>

<pre><code class="plaintext">unzip perl_pod.zip -d f:/perllib/lib</code></pre>

<p>This is used by the <code>perldoc</code> program (see <a href="perldoc.html">perldoc</a>), and may be used to generate HTML documentation usable by WWW browsers, and documentation in zillions of other formats: <code>info</code>, <code>LaTeX</code>, <code>Acrobat</code>, <code>FrameMaker</code> and so on. [Use programs such as <i>pod2latex</i> etc.]</p>

</dd>
<dt id="Perl-manual-in-.INF-format"><a class="permalink" href="perlos2.html#Perl-manual-in-.INF-format">#</a><a id="Perl1"></a>Perl manual in <i>.INF</i> format</dt>
<dd>

<pre><code class="plaintext">unzip perl_inf.zip -d d:/os2/book</code></pre>

<p>This directory should better be on <code>BOOKSHELF</code>.</p>

</dd>
<dt id="Pdksh"><a class="permalink" href="perlos2.html#Pdksh">#</a>Pdksh</dt>
<dd>

<pre><code class="plaintext">unzip perl_sh.zip -d f:/bin</code></pre>

<p>This is used by perl to run external commands which explicitly require shell, like the commands using <i>redirection</i> and <i>shell metacharacters</i>. It is also used instead of explicit <i>/bin/sh</i>.</p>

<p>Set <code>PERL_SH_DIR</code> (see <a href="perlos2.html#PERL_SH_DIR">&quot;<code>PERL_SH_DIR</code>&quot;</a>) if you move <i>sh.exe</i> from the above location.</p>

<p><b>Note.</b> It may be possible to use some other sh-compatible shell (untested).</p>

</dd>
</dl>

<p>After you installed the components you needed and updated the <i>Config.sys</i> correspondingly, you need to hand-edit <i>Config.pm</i>. This file resides somewhere deep in the location you installed your perl library, find it out by</p>

<pre><code>perl -MConfig -le &quot;print $INC{&#39;Config.pm&#39;}&quot;</code></pre>

<p>You need to correct all the entries which look like file paths (they currently start with <code>f:/</code>).</p>

<h2 id="Warning"><a class="permalink" href="perlos2.html#Warning">#</a><b>Warning</b></h2>

<p>The automatic and manual perl installation leave precompiled paths inside perl executables. While these paths are overwritable (see <a href="perlos2.html#PERLLIB_PREFIX">&quot;<code>PERLLIB_PREFIX</code>&quot;</a>, <a href="perlos2.html#PERL_SH_DIR">&quot;<code>PERL_SH_DIR</code>&quot;</a>), some people may prefer binary editing of paths inside the executables/DLLs.</p>

<h1 id="Accessing-documentation"><a class="permalink" href="perlos2.html#Accessing-documentation">#</a><a id="Accessing"></a>Accessing documentation</h1>

<p>Depending on how you built/installed perl you may have (otherwise identical) Perl documentation in the following formats:</p>

<h2 id="OS/2-.INF-file"><a class="permalink" href="perlos2.html#OS/2-.INF-file">#</a><a id="OS"></a><a id="OS-2-.INF-file"></a>OS/2 <i>.INF</i> file</h2>

<p>Most probably the most convenient form. Under OS/2 view it as</p>

<pre><code class="plaintext">view perl
view perl perlfunc
view perl less
view perl ExtUtils::MakeMaker</code></pre>

<p>(currently the last two may hit a wrong location, but this may improve soon). Under Win* see <a href="perlos2.html#SYNOPSIS">&quot;SYNOPSIS&quot;</a>.</p>

<p>If you want to build the docs yourself, and have <i>OS/2 toolkit</i>, run</p>

<pre><code class="plaintext">pod2ipf &gt; perl.ipf</code></pre>

<p>in <i>/perllib/lib/pod</i> directory, then</p>

<pre><code class="plaintext">ipfc /inf perl.ipf</code></pre>

<p>(Expect a lot of errors during the both steps.) Now move it on your BOOKSHELF path.</p>

<h2 id="Plain-text"><a class="permalink" href="perlos2.html#Plain-text">#</a><a id="Plain"></a>Plain text</h2>

<p>If you have perl documentation in the source form, perl utilities installed, and GNU groff installed, you may use</p>

<pre><code class="plaintext">perldoc perlfunc
perldoc less
perldoc ExtUtils::MakeMaker</code></pre>

<p>to access the perl documentation in the text form (note that you may get better results using perl manpages).</p>

<p>Alternately, try running pod2text on <i>.pod</i> files.</p>

<h2 id="Manpages"><a class="permalink" href="perlos2.html#Manpages">#</a>Manpages</h2>

<p>If you have <i>man</i> installed on your system, and you installed perl manpages, use something like this:</p>

<pre><code class="plaintext">man perlfunc
man 3 less
man ExtUtils.MakeMaker</code></pre>

<p>to access documentation for different components of Perl. Start with</p>

<pre><code class="plaintext">man perl</code></pre>

<p>Note that dot (<i>.</i>) is used as a package separator for documentation for packages, and as usual, sometimes you need to give the section - <code>3</code> above - to avoid shadowing by the <i>less(1) manpage</i>.</p>

<p>Make sure that the directory <b>above</b> the directory with manpages is on our <code>MANPATH</code>, like this</p>

<pre><code class="plaintext">set MANPATH=c:/man;f:/perllib/man</code></pre>

<p>for Perl manpages in <code>f:/perllib/man/man1/</code> etc.</p>

<h2 id="HTML"><a class="permalink" href="perlos2.html#HTML">#</a>HTML</h2>

<p>If you have some WWW browser available, installed the Perl documentation in the source form, and Perl utilities, you can build HTML docs. Cd to directory with <i>.pod</i> files, and do like this</p>

<pre><code class="plaintext">cd f:/perllib/lib/pod
pod2html</code></pre>

<p>After this you can direct your browser the file <i>perl.html</i> in this directory, and go ahead with reading docs, like this:</p>

<pre><code class="plaintext">explore file:///f:/perllib/lib/pod/perl.html</code></pre>

<p>Alternatively you may be able to get these docs prebuilt from CPAN.</p>

<h2 id="GNU-info-files"><a class="permalink" href="perlos2.html#GNU-info-files">#</a><a id="GNU"></a>GNU <code>info</code> files</h2>

<p>Users of Emacs would appreciate it very much, especially with <code>CPerl</code> mode loaded. You need to get latest <code>pod2texi</code> from <code>CPAN</code>, or, alternately, the prebuilt info pages.</p>

<h2 id="PDF-files"><a class="permalink" href="perlos2.html#PDF-files">#</a><a id="PDF"></a><i>PDF</i> files</h2>

<p>for <code>Acrobat</code> are available on CPAN (may be for slightly older version of perl).</p>

<h2 id="LaTeX-docs"><a class="permalink" href="perlos2.html#LaTeX-docs">#</a><a id="LaTeX"></a><code>LaTeX</code> docs</h2>

<p>can be constructed using <code>pod2latex</code>.</p>

<h1 id="BUILD"><a class="permalink" href="perlos2.html#BUILD">#</a>BUILD</h1>

<p>Here we discuss how to build Perl under OS/2.</p>

<h2 id="The-short-story"><a class="permalink" href="perlos2.html#The-short-story">#</a><a id="The"></a>The short story</h2>

<p>Assume that you are a seasoned porter, so are sure that all the necessary tools are already present on your system, and you know how to get the Perl source distribution. Untar it, change to the extract directory, and</p>

<pre><code class="plaintext">gnupatch -p0 &lt; os2\diff.configure
sh Configure -des -D prefix=f:/perllib
make
make test
make install
make aout_test
make aout_install</code></pre>

<p>This puts the executables in f:/perllib/bin. Manually move them to the <code>PATH</code>, manually move the built <i>perl*.dll</i> to <code>LIBPATH</code> (here for Perl DLL <i>*</i> is a not-very-meaningful hex checksum), and run</p>

<pre><code class="plaintext">make installcmd INSTALLCMDDIR=d:/ir/on/path</code></pre>

<p>Assuming that the <code>man</code>-files were put on an appropriate location, this completes the installation of minimal Perl system. (The binary distribution contains also a lot of additional modules, and the documentation in INF format.)</p>

<p>What follows is a detailed guide through these steps.</p>

<h2 id="Prerequisites1"><a class="permalink" href="perlos2.html#Prerequisites1">#</a>Prerequisites</h2>

<p>You need to have the latest EMX development environment, the full GNU tool suite (gawk renamed to awk, and GNU <i>find.exe</i> earlier on path than the OS/2 <i>find.exe</i>, same with <i>sort.exe</i>, to check use</p>

<pre><code class="plaintext">find --version
sort --version</code></pre>

<p>). You need the latest version of <i>pdksh</i> installed as <i>sh.exe</i>.</p>

<p>Check that you have <b>BSD</b> libraries and headers installed, and - optionally - Berkeley DB headers and libraries, and crypt.</p>

<p>Possible locations to get the files:</p>

<pre><code class="plaintext">ftp://ftp.uni-heidelberg.de/pub/os2/unix/
http://hobbes.nmsu.edu/h-browse.php?dir=/pub/os2
http://cd.textfiles.com/hobbesos29804/disk1/DEV32/
http://cd.textfiles.com/hobbesos29804/disk1/EMX09C/</code></pre>

<p>It is reported that the following archives contain enough utils to build perl: <i>gnufutil.zip</i>, <i>gnusutil.zip</i>, <i>gnututil.zip</i>, <i>gnused.zip</i>, <i>gnupatch.zip</i>, <i>gnuawk.zip</i>, <i>gnumake.zip</i>, <i>gnugrep.zip</i>, <i>bsddev.zip</i> and <i>ksh527rt.zip</i> (or a later version). Note that all these utilities are known to be available from LEO:</p>

<pre><code class="plaintext">ftp://crydee.sai.msu.ru/pub/comp/os/os2/leo/gnu/</code></pre>

<p>Note also that the <i>db.lib</i> and <i>db.a</i> from the EMX distribution are not suitable for multi-threaded compile (even single-threaded flavor of Perl uses multi-threaded C RTL, for compatibility with XFree86-OS/2). Get a corrected one from</p>

<pre><code class="plaintext">http://www.ilyaz.org/software/os2/db_mt.zip</code></pre>

<p>If you have <i>exactly the same version of Perl</i> installed already, make sure that no copies or perl are currently running. Later steps of the build may fail since an older version of <i>perl.dll</i> loaded into memory may be found. Running <code>make test</code> becomes meaningless, since the test are checking a previous build of perl (this situation is detected and reported by <i>os2/os2_base.t</i> test). Do not forget to unset <code>PERL_EMXLOAD_SEC</code> in environment.</p>

<p>Also make sure that you have <i>/tmp</i> directory on the current drive, and <i>.</i> directory in your <code>LIBPATH</code>. One may try to correct the latter condition by</p>

<pre><code class="plaintext">set BEGINLIBPATH .\.</code></pre>

<p>if you use something like <i>CMD.EXE</i> or latest versions of <i>4os2.exe</i>. (Setting BEGINLIBPATH to just <code>.</code> is ignored by the OS/2 kernel.)</p>

<p>Make sure your gcc is good for <code>-Zomf</code> linking: run <code>omflibs</code> script in <i>/emx/lib</i> directory.</p>

<p>Check that you have link386 installed. It comes standard with OS/2, but may be not installed due to customization. If typing</p>

<pre><code class="plaintext">link386</code></pre>

<p>shows you do not have it, do <i>Selective install</i>, and choose <code>Link object modules</code> in <i>Optional system utilities/More</i>. If you get into link386 prompts, press <code>Ctrl-C</code> to exit.</p>

<h2 id="Getting-perl-source"><a class="permalink" href="perlos2.html#Getting-perl-source">#</a><a id="Getting"></a>Getting perl source</h2>

<p>You need to fetch the latest perl source (including developers releases). With some probability it is located in</p>

<pre><code class="plaintext">http://www.cpan.org/src/
http://www.cpan.org/src/unsupported</code></pre>

<p>If not, you may need to dig in the indices to find it in the directory of the current maintainer.</p>

<p>Quick cycle of developers release may break the OS/2 build time to time, looking into</p>

<pre><code class="plaintext">http://www.cpan.org/ports/os2/</code></pre>

<p>may indicate the latest release which was publicly released by the maintainer. Note that the release may include some additional patches to apply to the current source of perl.</p>

<p>Extract it like this</p>

<pre><code class="plaintext">tar vzxf perl5.00409.tar.gz</code></pre>

<p>You may see a message about errors while extracting <i>Configure</i>. This is because there is a conflict with a similarly-named file <i>configure</i>.</p>

<p>Change to the directory of extraction.</p>

<h2 id="Application-of-the-patches"><a class="permalink" href="perlos2.html#Application-of-the-patches">#</a><a id="Application"></a>Application of the patches</h2>

<p>You need to apply the patches in <i>./os2/diff.*</i> like this:</p>

<pre><code class="plaintext">gnupatch -p0 &lt; os2\diff.configure</code></pre>

<p>You may also need to apply the patches supplied with the binary distribution of perl. It also makes sense to look on the perl5-porters mailing list for the latest OS/2-related patches (see <a href="http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/">http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/</a>). Such patches usually contain strings <code>/os2/</code> and <code>patch</code>, so it makes sense looking for these strings.</p>

<h2 id="Hand-editing"><a class="permalink" href="perlos2.html#Hand-editing">#</a><a id="Hand"></a>Hand-editing</h2>

<p>You may look into the file <i>./hints/os2.sh</i> and correct anything wrong you find there. I do not expect it is needed anywhere.</p>

<h2 id="Making"><a class="permalink" href="perlos2.html#Making">#</a>Making</h2>

<pre><code class="plaintext">sh Configure -des -D prefix=f:/perllib</code></pre>

<p><code>prefix</code> means: where to install the resulting perl library. Giving correct prefix you may avoid the need to specify <code>PERLLIB_PREFIX</code>, see <a href="perlos2.html#PERLLIB_PREFIX">&quot;<code>PERLLIB_PREFIX</code>&quot;</a>.</p>

<p><i>Ignore the message about missing <code>ln</code>, and about <code>-c</code> option to tr</i>. The latter is most probably already fixed, if you see it and can trace where the latter spurious warning comes from, please inform me.</p>

<p>Now</p>

<pre><code class="plaintext">make</code></pre>

<p>At some moment the built may die, reporting a <i>version mismatch</i> or <i>unable to run <i>perl</i></i>. This means that you do not have <i>.</i> in your LIBPATH, so <i>perl.exe</i> cannot find the needed <i>perl67B2.dll</i> (treat these hex digits as line noise). After this is fixed the build should finish without a lot of fuss.</p>

<h2 id="Testing"><a class="permalink" href="perlos2.html#Testing">#</a>Testing</h2>

<p>Now run</p>

<pre><code class="plaintext">make test</code></pre>

<p>All tests should succeed (with some of them skipped). If you have the same version of Perl installed, it is crucial that you have <code>.</code> early in your LIBPATH (or in BEGINLIBPATH), otherwise your tests will most probably test the wrong version of Perl.</p>

<p>Some tests may generate extra messages similar to</p>

<dl>

<dt id="A-lot-of-bad-free"><a class="permalink" href="perlos2.html#A-lot-of-bad-free">#</a><a id="A"></a>A lot of <code>bad free</code></dt>
<dd>

<p>in database tests related to Berkeley DB. <i>This should be fixed already.</i> If it persists, you may disable this warnings, see <a href="perlos2.html#PERL_BADFREE">&quot;<code>PERL_BADFREE</code>&quot;</a>.</p>

</dd>
<dt id="Process-terminated-by-SIGTERM/SIGINT"><a class="permalink" href="perlos2.html#Process-terminated-by-SIGTERM/SIGINT">#</a><a id="Process"></a><a id="Process-terminated-by-SIGTERM-SIGINT"></a>Process terminated by SIGTERM/SIGINT</dt>
<dd>

<p>This is a standard message issued by OS/2 applications. *nix applications die in silence. It is considered to be a feature. One can easily disable this by appropriate sighandlers.</p>

<p>However the test engine bleeds these message to screen in unexpected moments. Two messages of this kind <i>should</i> be present during testing.</p>

</dd>
</dl>

<p>To get finer test reports, call</p>

<pre><code class="plaintext">perl t/harness</code></pre>

<p>The report with <i>io/pipe.t</i> failing may look like this:</p>

<pre><code class="plaintext">Failed Test  Status Wstat Total Fail  Failed  List of failed
------------------------------------------------------------
io/pipe.t                    12    1   8.33%  9
7 tests skipped, plus 56 subtests skipped.
Failed 1/195 test scripts, 99.49% okay. 1/6542 subtests failed,
   99.98% okay.</code></pre>

<p>The reasons for most important skipped tests are:</p>

<dl>

<dt id="op/fs.t"><a class="permalink" href="perlos2.html#op/fs.t">#</a><a id="op"></a><a id="op-fs.t"></a><i>op/fs.t</i></dt>
<dd>

<dl>

<dt id="18"><a class="permalink" href="perlos2.html#18">#</a><a id="pod18"></a>18</dt>
<dd>

<p>Checks <code>atime</code> and <code>mtime</code> of <code>stat()</code> - unfortunately, HPFS provides only 2sec time granularity (for compatibility with FAT?).</p>

</dd>
<dt id="25"><a class="permalink" href="perlos2.html#25">#</a><a id="pod25"></a>25</dt>
<dd>

<p>Checks <code>truncate()</code> on a filehandle just opened for write - I do not know why this should or should not work.</p>

</dd>
</dl>

</dd>
<dt id="op/stat.t"><a class="permalink" href="perlos2.html#op/stat.t">#</a><a id="op1"></a><a id="op-stat.t"></a><i>op/stat.t</i></dt>
<dd>

<p>Checks <code>stat()</code>. Tests:</p>

<dl>

<dt id="4"><a class="permalink" href="perlos2.html#4">#</a><a id="pod4"></a>4</dt>
<dd>

<p>Checks <code>atime</code> and <code>mtime</code> of <code>stat()</code> - unfortunately, HPFS provides only 2sec time granularity (for compatibility with FAT?).</p>

</dd>
</dl>

</dd>
</dl>

<h2 id="Installing-the-built-perl"><a class="permalink" href="perlos2.html#Installing-the-built-perl">#</a><a id="Installing"></a>Installing the built perl</h2>

<p>If you haven&#39;t yet moved <code>perl*.dll</code> onto LIBPATH, do it now.</p>

<p>Run</p>

<pre><code class="plaintext">make install</code></pre>

<p>It would put the generated files into needed locations. Manually put <i>perl.exe</i>, <i>perl__.exe</i> and <i>perl___.exe</i> to a location on your PATH, <i>perl.dll</i> to a location on your LIBPATH.</p>

<p>Run</p>

<pre><code class="plaintext">make installcmd INSTALLCMDDIR=d:/ir/on/path</code></pre>

<p>to convert perl utilities to <i>.cmd</i> files and put them on PATH. You need to put <i>.EXE</i>-utilities on path manually. They are installed in <code>$prefix/bin</code>, here <code>$prefix</code> is what you gave to <i>Configure</i>, see <a href="perlos2.html#Making">&quot;Making&quot;</a>.</p>

<p>If you use <code>man</code>, either move the installed <i>*/man/</i> directories to your <code>MANPATH</code>, or modify <code>MANPATH</code> to match the location. (One could have avoided this by providing a correct <code>manpath</code> option to <i>./Configure</i>, or editing <i>./config.sh</i> between configuring and making steps.)</p>

<h2 id="a.out-style-build"><a class="permalink" href="perlos2.html#a.out-style-build">#</a><a id="a"></a><code>a.out</code>-style build</h2>

<p>Proceed as above, but make <i>perl_.exe</i> (see <a href="perlos2.html#perl_.exe">&quot;<i>perl_.exe</i>&quot;</a>) by</p>

<pre><code class="plaintext">make perl_</code></pre>

<p>test and install by</p>

<pre><code class="plaintext">make aout_test
make aout_install</code></pre>

<p>Manually put <i>perl_.exe</i> to a location on your PATH.</p>

<p><b>Note.</b> The build process for <code>perl_</code> <i>does not know</i> about all the dependencies, so you should make sure that anything is up-to-date, say, by doing</p>

<pre><code class="plaintext">make perl_dll</code></pre>

<p>first.</p>

<h1 id="Building-a-binary-distribution"><a class="permalink" href="perlos2.html#Building-a-binary-distribution">#</a><a id="Building"></a>Building a binary distribution</h1>

<p>[This section provides a short overview only...]</p>

<p>Building should proceed differently depending on whether the version of perl you install is already present and used on your system, or is a new version not yet used. The description below assumes that the version is new, so installing its DLLs and <i>.pm</i> files will not disrupt the operation of your system even if some intermediate steps are not yet fully working.</p>

<p>The other cases require a little bit more convoluted procedures. Below I suppose that the current version of Perl is <code>5.8.2</code>, so the executables are named accordingly.</p>

<ol>

<li><p>Fully build and test the Perl distribution. Make sure that no tests are failing with <code>test</code> and <code>aout_test</code> targets; fix the bugs in Perl and the Perl test suite detected by these tests. Make sure that <code>all_test</code> make target runs as clean as possible. Check that <i>os2/perlrexx.cmd</i> runs fine.</p>

</li>
<li><p>Fully install Perl, including <code>installcmd</code> target. Copy the generated DLLs to <code>LIBPATH</code>; copy the numbered Perl executables (as in <i>perl5.8.2.exe</i>) to <code>PATH</code>; copy <code>perl_.exe</code> to <code>PATH</code> as <code>perl_5.8.2.exe</code>. Think whether you need backward-compatibility DLLs. In most cases you do not need to install them yet; but sometime this may simplify the following steps.</p>

</li>
<li><p>Make sure that <code>CPAN.pm</code> can download files from CPAN. If not, you may need to manually install <code>Net::FTP</code>.</p>

</li>
<li><p>Install the bundle <code>Bundle::OS2_default</code></p>

<pre><code class="plaintext">perl5.8.2 -MCPAN -e &quot;install Bundle::OS2_default&quot; &lt; nul |&amp; tee 00cpan_i_1</code></pre>

<p>This may take a couple of hours on 1GHz processor (when run the first time). And this should not be necessarily a smooth procedure. Some modules may not specify required dependencies, so one may need to repeat this procedure several times until the results stabilize.</p>

<pre><code class="plaintext">perl5.8.2 -MCPAN -e &quot;install Bundle::OS2_default&quot; &lt; nul |&amp; tee 00cpan_i_2
perl5.8.2 -MCPAN -e &quot;install Bundle::OS2_default&quot; &lt; nul |&amp; tee 00cpan_i_3</code></pre>

<p>Even after they stabilize, some tests may fail.</p>

<p>Fix as many discovered bugs as possible. Document all the bugs which are not fixed, and all the failures with unknown reasons. Inspect the produced logs <i>00cpan_i_1</i> to find suspiciously skipped tests, and other fishy events.</p>

<p>Keep in mind that <i>installation</i> of some modules may fail too: for example, the DLLs to update may be already loaded by <i>CPAN.pm</i>. Inspect the <code>install</code> logs (in the example above <i>00cpan_i_1</i> etc) for errors, and install things manually, as in</p>

<pre><code>cd $CPANHOME/.cpan/build/Digest-MD5-2.31
make install</code></pre>

<p>Some distributions may fail some tests, but you may want to install them anyway (as above, or via <code>force install</code> command of <code>CPAN.pm</code> shell-mode).</p>

<p>Since this procedure may take quite a long time to complete, it makes sense to &quot;freeze&quot; your CPAN configuration by disabling periodic updates of the local copy of CPAN index: set <code>index_expire</code> to some big value (I use 365), then save the settings</p>

<pre><code class="plaintext">CPAN&gt; o conf index_expire 365
CPAN&gt; o conf commit</code></pre>

<p>Reset back to the default value <code>1</code> when you are finished.</p>

</li>
<li><p>When satisfied with the results, rerun the <code>installcmd</code> target. Now you can copy <code>perl5.8.2.exe</code> to <code>perl.exe</code>, and install the other OMF-build executables: <code>perl__.exe</code> etc. They are ready to be used.</p>

</li>
<li><p>Change to the <code>./pod</code> directory of the build tree, download the Perl logo <i>CamelGrayBig.BMP</i>, and run</p>

<pre><code class="plaintext">( perl2ipf &gt; perl.ipf ) |&amp; tee 00ipf
ipfc /INF perl.ipf |&amp; tee 00inf</code></pre>

<p>This produces the Perl docs online book <code>perl.INF</code>. Install in on <code>BOOKSHELF</code> path.</p>

</li>
<li><p>Now is the time to build statically linked executable <i>perl_.exe</i> which includes newly-installed via <code>Bundle::OS2_default</code> modules. Doing testing via <code>CPAN.pm</code> is going to be painfully slow, since it statically links a new executable per XS extension.</p>

<p>Here is a possible workaround: create a toplevel <i>Makefile.PL</i> in <i>$CPANHOME/.cpan/build/</i> with contents being (compare with <a href="perlos2.html#Making-executables-with-a-custom-collection-of-statically-loaded-extensions">&quot;Making executables with a custom collection of statically loaded extensions&quot;</a>)</p>

<pre><code>use ExtUtils::MakeMaker;
WriteMakefile NAME =&gt; &#39;dummy&#39;;</code></pre>

<p>execute this as</p>

<pre><code class="plaintext">perl_5.8.2.exe Makefile.PL &lt;nul |&amp; tee 00aout_c1
make -k all test &lt;nul |&amp; 00aout_t1</code></pre>

<p>Again, this procedure should not be absolutely smooth. Some <code>Makefile.PL</code>&#39;s in subdirectories may be buggy, and would not run as &quot;child&quot; scripts. The interdependency of modules can strike you; however, since non-XS modules are already installed, the prerequisites of most modules have a very good chance to be present.</p>

<p>If you discover some glitches, move directories of problematic modules to a different location; if these modules are non-XS modules, you may just ignore them - they are already installed; the remaining, XS, modules you need to install manually one by one.</p>

<p>After each such removal you need to rerun the <code>Makefile.PL</code>/<code>make</code> process; usually this procedure converges soon. (But be sure to convert all the necessary external C libraries from <i>.lib</i> format to <i>.a</i> format: run one of</p>

<pre><code class="plaintext">emxaout foo.lib
emximp -o foo.a foo.lib</code></pre>

<p>whichever is appropriate.) Also, make sure that the DLLs for external libraries are usable with executables compiled without <code>-Zmtd</code> options.</p>

<p>When you are sure that only a few subdirectories lead to failures, you may want to add <code>-j4</code> option to <code>make</code> to speed up skipping subdirectories with already finished build.</p>

<p>When you are satisfied with the results of tests, install the build C libraries for extensions:</p>

<pre><code class="plaintext">make install |&amp; tee 00aout_i</code></pre>

<p>Now you can rename the file <i>./perl.exe</i> generated during the last phase to <i>perl_5.8.2.exe</i>; place it on <code>PATH</code>; if there is an inter-dependency between some XS modules, you may need to repeat the <code>test</code>/<code>install</code> loop with this new executable and some excluded modules - until the procedure converges.</p>

<p>Now you have all the necessary <i>.a</i> libraries for these Perl modules in the places where Perl builder can find it. Use the perl builder: change to an empty directory, create a &quot;dummy&quot; <i>Makefile.PL</i> again, and run</p>

<pre><code class="plaintext">perl_5.8.2.exe Makefile.PL |&amp; tee 00c
make perl		     |&amp; tee 00p</code></pre>

<p>This should create an executable <i>./perl.exe</i> with all the statically loaded extensions built in. Compare the generated <i>perlmain.c</i> files to make sure that during the iterations the number of loaded extensions only increases. Rename <i>./perl.exe</i> to <i>perl_5.8.2.exe</i> on <code>PATH</code>.</p>

<p>When it converges, you got a functional variant of <i>perl_5.8.2.exe</i>; copy it to <code>perl_.exe</code>. You are done with generation of the local Perl installation.</p>

</li>
<li><p>Make sure that the installed modules are actually installed in the location of the new Perl, and are not inherited from entries of @INC given for inheritance from the older versions of Perl: set <code>PERLLIB_582_PREFIX</code> to redirect the new version of Perl to a new location, and copy the installed files to this new location. Redo the tests to make sure that the versions of modules inherited from older versions of Perl are not needed.</p>

<p>Actually, the log output of <a href="http://man.he.net/man1/pod2ipf">pod2ipf(1)</a> during the step 6 gives a very detailed info about which modules are loaded from which place; so you may use it as an additional verification tool.</p>

<p>Check that some temporary files did not make into the perl install tree. Run something like this</p>

<pre><code class="plaintext">pfind . -f &quot;!(/\.(pm|pl|ix|al|h|a|lib|txt|pod|imp|bs|dll|ld|bs|inc|xbm|yml|cgi|uu|e2x|skip|packlist|eg|cfg|html|pub|enc|all|ini|po|pot)$/i or /^\w+$/&quot;) | less</code></pre>

<p>in the install tree (both top one and <i>sitelib</i> one).</p>

<p>Compress all the DLLs with <i>lxlite</i>. The tiny <i>.exe</i> can be compressed with <code>/c:max</code> (the bug only appears when there is a fixup in the last 6 bytes of a page (?); since the tiny executables are much smaller than a page, the bug will not hit). Do not compress <code>perl_.exe</code> - it would not work under DOS.</p>

</li>
<li><p>Now you can generate the binary distribution. This is done by running the test of the CPAN distribution <code>OS2::SoftInstaller</code>. Tune up the file <i>test.pl</i> to suit the layout of current version of Perl first. Do not forget to pack the necessary external DLLs accordingly. Include the description of the bugs and test suite failures you could not fix. Include the small-stack versions of Perl executables from Perl build directory.</p>

<p>Include <i>perl5.def</i> so that people can relink the perl DLL preserving the binary compatibility, or can create compatibility DLLs. Include the diff files (<code>diff -pu old new</code>) of fixes you did so that people can rebuild your version. Include <i>perl5.map</i> so that one can use remote debugging.</p>

</li>
<li><p>Share what you did with the other people. Relax. Enjoy fruits of your work.</p>

</li>
<li><p>Brace yourself for thanks, bug reports, hate mail and spam coming as result of the previous step. No good deed should remain unpunished!</p>

</li>
</ol>

<h1 id="Building-custom-.EXE-files"><a class="permalink" href="perlos2.html#Building-custom-.EXE-files">#</a><a id="Building1"></a>Building custom <i>.EXE</i> files</h1>

<p>The Perl executables can be easily rebuilt at any moment. Moreover, one can use the <i>embedding</i> interface (see <a href="perlembed.html">perlembed</a>) to make very customized executables.</p>

<h2 id="Making-executables-with-a-custom-collection-of-statically-loaded-extensions"><a class="permalink" href="perlos2.html#Making-executables-with-a-custom-collection-of-statically-loaded-extensions">#</a><a id="Making1"></a>Making executables with a custom collection of statically loaded extensions</h2>

<p>It is a little bit easier to do so while <i>decreasing</i> the list of statically loaded extensions. We discuss this case only here.</p>

<ol>

<li><p>Change to an empty directory, and create a placeholder &lt;Makefile.PL&gt;:</p>

<pre><code>use ExtUtils::MakeMaker;
WriteMakefile NAME =&gt; &#39;dummy&#39;;</code></pre>

</li>
<li><p>Run it with the flavor of Perl (<i>perl.exe</i> or <i>perl_.exe</i>) you want to rebuild.</p>

<pre><code class="plaintext">perl_ Makefile.PL</code></pre>

</li>
<li><p>Ask it to create new Perl executable:</p>

<pre><code class="plaintext">make perl</code></pre>

<p>(you may need to manually add <code>PERLTYPE=-DPERL_CORE</code> to this commandline on some versions of Perl; the symptom is that the command-line globbing does not work from OS/2 shells with the newly-compiled executable; check with</p>

<pre><code>.\perl.exe -wle &quot;print for @ARGV&quot; *</code></pre>

<p>).</p>

</li>
<li><p>The previous step created <i>perlmain.c</i> which contains a list of newXS() calls near the end. Removing unnecessary calls, and rerunning</p>

<pre><code class="plaintext">make perl</code></pre>

<p>will produce a customized executable.</p>

</li>
</ol>

<h2 id="Making-executables-with-a-custom-search-paths"><a class="permalink" href="perlos2.html#Making-executables-with-a-custom-search-paths">#</a><a id="Making2"></a>Making executables with a custom search-paths</h2>

<p>The default perl executable is flexible enough to support most usages. However, one may want something yet more flexible; for example, one may want to find Perl DLL relatively to the location of the EXE file; or one may want to ignore the environment when setting the Perl-library search patch, etc.</p>

<p>If you fill comfortable with <i>embedding</i> interface (see <a href="perlembed.html">perlembed</a>), such things are easy to do repeating the steps outlined in <a href="perlos2.html#Making-executables-with-a-custom-collection-of-statically-loaded-extensions">&quot;Making executables with a custom collection of statically loaded extensions&quot;</a>, and doing more comprehensive edits to main() of <i>perlmain.c</i>. The people with little desire to understand Perl can just rename main(), and do necessary modification in a custom main() which calls the renamed function in appropriate time.</p>

<p>However, there is a third way: perl DLL exports the main() function and several callbacks to customize the search path. Below is a complete example of a &quot;Perl loader&quot; which</p>

<ol>

<li><p>Looks for Perl DLL in the directory <code>$exedir/../dll</code>;</p>

</li>
<li><p>Prepends the above directory to <code>BEGINLIBPATH</code>;</p>

</li>
<li><p>Fails if the Perl DLL found via <code>BEGINLIBPATH</code> is different from what was loaded on step 1; e.g., another process could have loaded it from <code>LIBPATH</code> or from a different value of <code>BEGINLIBPATH</code>. In these cases one needs to modify the setting of the system so that this other process either does not run, or loads the DLL from <code>BEGINLIBPATH</code> with <code>LIBPATHSTRICT=T</code> (available with kernels after September 2000).</p>

</li>
<li><p>Loads Perl library from <code>$exedir/../dll/lib/</code>.</p>

</li>
<li><p>Uses Bourne shell from <code>$exedir/../dll/sh/ksh.exe</code>.</p>

</li>
</ol>

<p>For best results compile the C file below with the same options as the Perl DLL. However, a lot of functionality will work even if the executable is not an EMX applications, e.g., if compiled with</p>

<pre><code class="plaintext">gcc -Wall -DDOSISH -DOS2=1 -O2 -s -Zomf -Zsys perl-starter.c \
  -DPERL_DLL_BASENAME=\&quot;perl312F\&quot; -Zstack 8192 -Zlinker /PM:VIO</code></pre>

<p>Here is the sample C file:</p>

<pre><code>#define INCL_DOS
#define INCL_NOPM
/* These are needed for compile if os2.h includes os2tk.h, not
 * os2emx.h */
#define INCL_DOSPROCESS
#include &lt;os2.h&gt;

#include &quot;EXTERN.h&quot;
#define PERL_IN_MINIPERLMAIN_C
#include &quot;perl.h&quot;

static char *me;
HMODULE handle;

static void
die_with(char *msg1, char *msg2, char *msg3, char *msg4)
{
   ULONG c;
   char *s = &quot; error: &quot;;

   DosWrite(2, me, strlen(me), &amp;c);
   DosWrite(2, s, strlen(s), &amp;c);
   DosWrite(2, msg1, strlen(msg1), &amp;c);
   DosWrite(2, msg2, strlen(msg2), &amp;c);
   DosWrite(2, msg3, strlen(msg3), &amp;c);
   DosWrite(2, msg4, strlen(msg4), &amp;c);
   DosWrite(2, &quot;\r\n&quot;, 2, &amp;c);
   exit(255);
}

typedef ULONG (*fill_extLibpath_t)(int type,
                                   char *pre,
                                   char *post,
                                   int replace,
                                   char *msg);
typedef int (*main_t)(int type, char *argv[], char *env[]);
typedef int (*handler_t)(void* data, int which);

#ifndef PERL_DLL_BASENAME
#  define PERL_DLL_BASENAME &quot;perl&quot;
#endif

static HMODULE
load_perl_dll(char *basename)
{
    char buf[300], fail[260];
    STRLEN l, dirl;
    fill_extLibpath_t f;
    ULONG rc_fullname;
    HMODULE handle, handle1;

    if (_execname(buf, sizeof(buf) - 13) != 0)
        die_with(&quot;Can&#39;t find full path: &quot;, strerror(errno), &quot;&quot;, &quot;&quot;);
    /* XXXX Fill &#39;me&#39; with new value */
    l = strlen(buf);
    while (l &amp;&amp; buf[l-1] != &#39;/&#39; &amp;&amp; buf[l-1] != &#39;\\&#39;)
        l--;
    dirl = l - 1;
    strcpy(buf + l, basename);
    l += strlen(basename);
    strcpy(buf + l, &quot;.dll&quot;);
    if ( (rc_fullname = DosLoadModule(fail, sizeof fail, buf, &amp;handle))
                                                                   != 0
         &amp;&amp; DosLoadModule(fail, sizeof fail, basename, &amp;handle) != 0 )
        die_with(&quot;Can&#39;t load DLL &quot;, buf, &quot;&quot;, &quot;&quot;);
    if (rc_fullname)
        return handle;    /* was loaded with short name; all is fine */
    if (DosQueryProcAddr(handle, 0, &quot;fill_extLibpath&quot;, (PFN*)&amp;f))
        die_with(buf,
                 &quot;: DLL exports no symbol &quot;,
                 &quot;fill_extLibpath&quot;,
                 &quot;&quot;);
    buf[dirl] = 0;
    if (f(0 /*BEGINLIBPATH*/, buf /* prepend */, NULL /* append */,
          0 /* keep old value */, me))
        die_with(me, &quot;: prepending BEGINLIBPATH&quot;, &quot;&quot;, &quot;&quot;);
    if (DosLoadModule(fail, sizeof fail, basename, &amp;handle1) != 0)
        die_with(me,
                 &quot;: finding perl DLL again via BEGINLIBPATH&quot;,
                 &quot;&quot;,
                 &quot;&quot;);
    buf[dirl] = &#39;\\&#39;;
    if (handle1 != handle) {
        if (DosQueryModuleName(handle1, sizeof(fail), fail))
            strcpy(fail, &quot;???&quot;);
        die_with(buf,
                 &quot;:\n\tperl DLL via BEGINLIBPATH is different: \n\t&quot;,
                 fail,
                 &quot;\n\tYou may need to manipulate global BEGINLIBPATH&quot;
                    &quot; and LIBPATHSTRICT&quot;
                    &quot;\n\tso that the other copy is loaded via&quot;
                    BEGINLIBPATH.&quot;);
    }
    return handle;
}

int
main(int argc, char **argv, char **env)
{
    main_t f;
    handler_t h;

    me = argv[0];
    /**/
    handle = load_perl_dll(PERL_DLL_BASENAME);

    if (DosQueryProcAddr(handle,
                         0,
                         &quot;Perl_OS2_handler_install&quot;,
                         (PFN*)&amp;h))
        die_with(PERL_DLL_BASENAME,
                 &quot;: DLL exports no symbol &quot;,
                 &quot;Perl_OS2_handler_install&quot;,
                 &quot;&quot;);
    if ( !h((void *)&quot;~installprefix&quot;, Perlos2_handler_perllib_from)
         || !h((void *)&quot;~dll&quot;, Perlos2_handler_perllib_to)
         || !h((void *)&quot;~dll/sh/ksh.exe&quot;, Perlos2_handler_perl_sh) )
        die_with(PERL_DLL_BASENAME,
                 &quot;: Can&#39;t install @INC manglers&quot;,
                 &quot;&quot;,
                 &quot;&quot;);
    if (DosQueryProcAddr(handle, 0, &quot;dll_perlmain&quot;, (PFN*)&amp;f))
        die_with(PERL_DLL_BASENAME,
                 &quot;: DLL exports no symbol &quot;,
                 &quot;dll_perlmain&quot;,
                 &quot;&quot;);
    return f(argc, argv, env);
}</code></pre>

<h1 id="Build-FAQ"><a class="permalink" href="perlos2.html#Build-FAQ">#</a><a id="Build"></a>Build FAQ</h1>

<h2 id="Some-/-became-\-in-pdksh."><a class="permalink" href="perlos2.html#Some-/-became-%5C-in-pdksh.">#</a><a id="Some"></a><a id="Some-became-in-pdksh"></a>Some <code>/</code> became <code>\</code> in pdksh.</h2>

<p>You have a very old pdksh. See <a href="perlos2.html#Prerequisites">&quot;Prerequisites&quot;</a>.</p>

<h2 id="&#39;errno&#39;-unresolved-external"><a class="permalink" href="perlos2.html#&#39;errno&#39;-unresolved-external">#</a><a id="errno---unresolved-external"></a><code>&#39;errno&#39;</code> - unresolved external</h2>

<p>You do not have MT-safe <i>db.lib</i>. See <a href="perlos2.html#Prerequisites">&quot;Prerequisites&quot;</a>.</p>

<h2 id="Problems-with-tr-or-sed"><a class="permalink" href="perlos2.html#Problems-with-tr-or-sed">#</a><a id="Problems"></a>Problems with tr or sed</h2>

<p>reported with very old version of tr and sed.</p>

<h2 id="Some-problem-(forget-which-;-)"><a class="permalink" href="perlos2.html#Some-problem-(forget-which-;-)">#</a><a id="Some1"></a><a id="Some-problem-forget-which"></a>Some problem (forget which ;-)</h2>

<p>You have an older version of <i>perl.dll</i> on your LIBPATH, which broke the build of extensions.</p>

<h2 id="Library-...-not-found"><a class="permalink" href="perlos2.html#Library-...-not-found">#</a><a id="Library"></a>Library ... not found</h2>

<p>You did not run <code>omflibs</code>. See <a href="perlos2.html#Prerequisites">&quot;Prerequisites&quot;</a>.</p>

<h2 id="Segfault-in-make"><a class="permalink" href="perlos2.html#Segfault-in-make">#</a><a id="Segfault"></a>Segfault in make</h2>

<p>You use an old version of GNU make. See <a href="perlos2.html#Prerequisites">&quot;Prerequisites&quot;</a>.</p>

<h2 id="op/sprintf-test-failure"><a class="permalink" href="perlos2.html#op/sprintf-test-failure">#</a><a id="op2"></a><a id="op-sprintf-test-failure"></a>op/sprintf test failure</h2>

<p>This can result from a bug in emx sprintf which was fixed in 0.9d fix 03.</p>

<h1 id="Specific-(mis)features-of-OS/2-port"><a class="permalink" href="perlos2.html#Specific-(mis)features-of-OS/2-port">#</a><a id="Specific"></a><a id="Specific-mis-features-of-OS-2-port"></a>Specific (mis)features of OS/2 port</h1>

<h2 id="setpriority,-getpriority"><a class="permalink" href="perlos2.html#setpriority,-getpriority">#</a><a id="setpriority"></a><a id="setpriority-getpriority"></a><code>setpriority</code>, <code>getpriority</code></h2>

<p>Note that these functions are compatible with *nix, not with the older ports of &#39;94 - 95. The priorities are absolute, go from 32 to -95, lower is quicker. 0 is the default priority.</p>

<p><b>WARNING</b>. Calling <code>getpriority</code> on a non-existing process could lock the system before Warp3 fixpak22. Starting with Warp3, Perl will use a workaround: it aborts getpriority() if the process is not present. This is not possible on older versions <code>2.*</code>, and has a race condition anyway.</p>

<h2 id="system()"><a class="permalink" href="perlos2.html#system()">#</a><a id="system"></a><code>system()</code></h2>

<p>Multi-argument form of <code>system()</code> allows an additional numeric argument. The meaning of this argument is described in <a href="./OS2::Process.html">OS2::Process</a>.</p>

<p>When finding a program to run, Perl first asks the OS to look for executables on <code>PATH</code> (OS/2 adds extension <i>.exe</i> if no extension is present). If not found, it looks for a script with possible extensions added in this order: no extension, <i>.cmd</i>, <i>.btm</i>, <i>.bat</i>, <i>.pl</i>. If found, Perl checks the start of the file for magic strings <code>&quot;#!&quot;</code> and <code>&quot;extproc &quot;</code>. If found, Perl uses the rest of the first line as the beginning of the command line to run this script. The only mangling done to the first line is extraction of arguments (currently up to 3), and ignoring of the path-part of the &quot;interpreter&quot; name if it can&#39;t be found using the full path.</p>

<p>E.g., <code>system &#39;foo&#39;, &#39;bar&#39;, &#39;baz&#39;</code> may lead Perl to finding <i>C:/emx/bin/foo.cmd</i> with the first line being</p>

<pre><code class="plaintext">extproc /bin/bash    -x   -c</code></pre>

<p>If <i>/bin/bash.exe</i> is not found, then Perl looks for an executable <i>bash.exe</i> on <code>PATH</code>. If found in <i>C:/emx.add/bin/bash.exe</i>, then the above system() is translated to</p>

<pre><code class="plaintext">system qw(C:/emx.add/bin/bash.exe -x -c C:/emx/bin/foo.cmd bar baz)</code></pre>

<p>One additional translation is performed: instead of <i>/bin/sh</i> Perl uses the hardwired-or-customized shell (see <a href="perlos2.html#PERL_SH_DIR">&quot;<code>PERL_SH_DIR</code>&quot;</a>).</p>

<p>The above search for &quot;interpreter&quot; is recursive: if <i>bash</i> executable is not found, but <i>bash.btm</i> is found, Perl will investigate its first line etc. The only hardwired limit on the recursion depth is implicit: there is a limit 4 on the number of additional arguments inserted before the actual arguments given to system(). In particular, if no additional arguments are specified on the &quot;magic&quot; first lines, then the limit on the depth is 4.</p>

<p>If Perl finds that the found executable is of PM type when the current session is not, it will start the new process in a separate session of necessary type. Call via <code>OS2::Process</code> to disable this magic.</p>

<p><b>WARNING</b>. Due to the described logic, you need to explicitly specify <i>.com</i> extension if needed. Moreover, if the executable <i>perl5.6.1</i> is requested, Perl will not look for <i>perl5.6.1.exe</i>. [This may change in the future.]</p>

<h2 id="extproc-on-the-first-line"><a class="permalink" href="perlos2.html#extproc-on-the-first-line">#</a><a id="extproc"></a><code>extproc</code> on the first line</h2>

<p>If the first chars of a Perl script are <code>&quot;extproc &quot;</code>, this line is treated as <code>#!</code>-line, thus all the switches on this line are processed (twice if script was started via cmd.exe). See <a href="perlrun.html#DESCRIPTION">&quot;DESCRIPTION&quot; in perlrun</a>.</p>

<h2 id="Additional-modules:"><a class="permalink" href="perlos2.html#Additional-modules:">#</a><a id="Additional1"></a><a id="Additional-modules"></a>Additional modules:</h2>

<p><a href="./OS2::Process.html">OS2::Process</a>, <a href="./OS2::DLL.html">OS2::DLL</a>, <a href="./OS2::REXX.html">OS2::REXX</a>, <a href="./OS2::PrfDB.html">OS2::PrfDB</a>, <a href="./OS2::ExtAttr.html">OS2::ExtAttr</a>. These modules provide access to additional numeric argument for <code>system</code> and to the information about the running process, to DLLs having functions with REXX signature and to the REXX runtime, to OS/2 databases in the <i>.INI</i> format, and to Extended Attributes.</p>

<p>Two additional extensions by Andreas Kaiser, <code>OS2::UPM</code>, and <code>OS2::FTP</code>, are included into <code>ILYAZ</code> directory, mirrored on CPAN. Other OS/2-related extensions are available too.</p>

<h2 id="Prebuilt-methods:"><a class="permalink" href="perlos2.html#Prebuilt-methods:">#</a><a id="Prebuilt"></a><a id="Prebuilt-methods"></a>Prebuilt methods:</h2>

<dl>

<dt id="File::Copy::syscopy"><a class="permalink" href="perlos2.html#File::Copy::syscopy">#</a><a id="File"></a><code>File::Copy::syscopy</code></dt>
<dd>

<p>used by <code>File::Copy::copy</code>, see <a href="./File::Copy.html">File::Copy</a>.</p>

</dd>
<dt id="DynaLoader::mod2fname"><a class="permalink" href="perlos2.html#DynaLoader::mod2fname">#</a><a id="DynaLoader"></a><code>DynaLoader::mod2fname</code></dt>
<dd>

<p>used by <code>DynaLoader</code> for DLL name mangling.</p>

</dd>
<dt id="Cwd::current_drive()"><a class="permalink" href="perlos2.html#Cwd::current_drive()">#</a><a id="Cwd"></a><a id="Cwd::current_drive"></a><code>Cwd::current_drive()</code></dt>
<dd>

<p>Self explanatory.</p>

</dd>
<dt id="Cwd::sys_chdir(name)"><a class="permalink" href="perlos2.html#Cwd::sys_chdir(name)">#</a><a id="Cwd1"></a><a id="Cwd::sys_chdir-name"></a><code>Cwd::sys_chdir(name)</code></dt>
<dd>

<p>leaves drive as it is.</p>

</dd>
<dt id="Cwd::change_drive(name)"><a class="permalink" href="perlos2.html#Cwd::change_drive(name)">#</a><a id="Cwd2"></a><a id="Cwd::change_drive-name"></a><code>Cwd::change_drive(name)</code></dt>
<dd>

<p>changes the &quot;current&quot; drive.</p>

</dd>
<dt id="Cwd::sys_is_absolute(name)"><a class="permalink" href="perlos2.html#Cwd::sys_is_absolute(name)">#</a><a id="Cwd3"></a><a id="Cwd::sys_is_absolute-name"></a><code>Cwd::sys_is_absolute(name)</code></dt>
<dd>

<p>means has drive letter and is_rooted.</p>

</dd>
<dt id="Cwd::sys_is_rooted(name)"><a class="permalink" href="perlos2.html#Cwd::sys_is_rooted(name)">#</a><a id="Cwd4"></a><a id="Cwd::sys_is_rooted-name"></a><code>Cwd::sys_is_rooted(name)</code></dt>
<dd>

<p>means has leading <code>[/\\]</code> (maybe after a drive-letter:).</p>

</dd>
<dt id="Cwd::sys_is_relative(name)"><a class="permalink" href="perlos2.html#Cwd::sys_is_relative(name)">#</a><a id="Cwd5"></a><a id="Cwd::sys_is_relative-name"></a><code>Cwd::sys_is_relative(name)</code></dt>
<dd>

<p>means changes with current dir.</p>

</dd>
<dt id="Cwd::sys_cwd(name)"><a class="permalink" href="perlos2.html#Cwd::sys_cwd(name)">#</a><a id="Cwd6"></a><a id="Cwd::sys_cwd-name"></a><code>Cwd::sys_cwd(name)</code></dt>
<dd>

<p>Interface to cwd from EMX. Used by <code>Cwd::cwd</code>.</p>

</dd>
<dt id="Cwd::sys_abspath(name,-dir)"><a class="permalink" href="perlos2.html#Cwd::sys_abspath(name,-dir)">#</a><a id="Cwd7"></a><a id="Cwd::sys_abspath-name-dir"></a><code>Cwd::sys_abspath(name, dir)</code></dt>
<dd>

<p>Really really odious function to implement. Returns absolute name of file which would have <code>name</code> if CWD were <code>dir</code>. <code>Dir</code> defaults to the current dir.</p>

</dd>
<dt id="Cwd::extLibpath([type])"><a class="permalink" href="perlos2.html#Cwd::extLibpath(%5Btype%5D)">#</a><a id="Cwd8"></a><a id="Cwd::extLibpath-type"></a><code>Cwd::extLibpath([type])</code></dt>
<dd>

<p>Get current value of extended library search path. If <code>type</code> is present and positive, works with <code>END_LIBPATH</code>, if negative, works with <code>LIBPATHSTRICT</code>, otherwise with <code>BEGIN_LIBPATH</code>.</p>

</dd>
<dt id="Cwd::extLibpath_set(-path-[,-type-]-)"><a class="permalink" href="perlos2.html#Cwd::extLibpath_set(-path-%5B,-type-%5D-)">#</a><a id="Cwd9"></a><a id="Cwd::extLibpath_set-path-type"></a><code>Cwd::extLibpath_set( path [, type ] )</code></dt>
<dd>

<p>Set current value of extended library search path. If <code>type</code> is present and positive, works with &lt;END_LIBPATH&gt;, if negative, works with <code>LIBPATHSTRICT</code>, otherwise with <code>BEGIN_LIBPATH</code>.</p>

</dd>
<dt id="OS2::Error(do_harderror,do_exception)"><a class="permalink" href="perlos2.html#OS2::Error(do_harderror,do_exception)">#</a><a id="OS2"></a><a id="OS2::Error-do_harderror-do_exception"></a><code>OS2::Error(do_harderror,do_exception)</code></dt>
<dd>

<p>Returns <code>undef</code> if it was not called yet, otherwise bit 1 is set if on the previous call do_harderror was enabled, bit 2 is set if on previous call do_exception was enabled.</p>

<p>This function enables/disables error popups associated with hardware errors (Disk not ready etc.) and software exceptions.</p>

<p>I know of no way to find out the state of popups <i>before</i> the first call to this function.</p>

</dd>
<dt id="OS2::Errors2Drive(drive)"><a class="permalink" href="perlos2.html#OS2::Errors2Drive(drive)">#</a><a id="OS21"></a><a id="OS2::Errors2Drive-drive"></a><code>OS2::Errors2Drive(drive)</code></dt>
<dd>

<p>Returns <code>undef</code> if it was not called yet, otherwise return false if errors were not requested to be written to a hard drive, or the drive letter if this was requested.</p>

<p>This function may redirect error popups associated with hardware errors (Disk not ready etc.) and software exceptions to the file POPUPLOG.OS2 at the root directory of the specified drive. Overrides OS2::Error() specified by individual programs. Given argument undef will disable redirection.</p>

<p>Has global effect, persists after the application exits.</p>

<p>I know of no way to find out the state of redirection of popups to the disk <i>before</i> the first call to this function.</p>

</dd>
<dt id="OS2::SysInfo()"><a class="permalink" href="perlos2.html#OS2::SysInfo()">#</a><a id="OS22"></a><a id="OS2::SysInfo"></a>OS2::SysInfo()</dt>
<dd>

<p>Returns a hash with system information. The keys of the hash are</p>

<pre><code class="plaintext">MAX_PATH_LENGTH, MAX_TEXT_SESSIONS, MAX_PM_SESSIONS,
MAX_VDM_SESSIONS, BOOT_DRIVE, DYN_PRI_VARIATION,
MAX_WAIT, MIN_SLICE, MAX_SLICE, PAGE_SIZE,
VERSION_MAJOR, VERSION_MINOR, VERSION_REVISION,
MS_COUNT, TIME_LOW, TIME_HIGH, TOTPHYSMEM, TOTRESMEM,
TOTAVAILMEM, MAXPRMEM, MAXSHMEM, TIMER_INTERVAL,
MAX_COMP_LENGTH, FOREGROUND_FS_SESSION,
FOREGROUND_PROCESS</code></pre>

</dd>
<dt id="OS2::BootDrive()"><a class="permalink" href="perlos2.html#OS2::BootDrive()">#</a><a id="OS23"></a><a id="OS2::BootDrive"></a>OS2::BootDrive()</dt>
<dd>

<p>Returns a letter without colon.</p>

</dd>
<dt id="OS2::MorphPM(serve),-OS2::UnMorphPM(serve)"><a class="permalink" href="perlos2.html#OS2::MorphPM(serve),-OS2::UnMorphPM(serve)">#</a><a id="OS24"></a><a id="OS2::MorphPM-serve-OS2::UnMorphPM-serve"></a><code>OS2::MorphPM(serve)</code>, <code>OS2::UnMorphPM(serve)</code></dt>
<dd>

<p>Transforms the current application into a PM application and back. The argument true means that a real message loop is going to be served. OS2::MorphPM() returns the PM message queue handle as an integer.</p>

<p>See <a href="perlos2.html#Centralized-management-of-resources">&quot;Centralized management of resources&quot;</a> for additional details.</p>

</dd>
<dt id="OS2::Serve_Messages(force)"><a class="permalink" href="perlos2.html#OS2::Serve_Messages(force)">#</a><a id="OS25"></a><a id="OS2::Serve_Messages-force"></a><code>OS2::Serve_Messages(force)</code></dt>
<dd>

<p>Fake on-demand retrieval of outstanding PM messages. If <code>force</code> is false, will not dispatch messages if a real message loop is known to be present. Returns number of messages retrieved.</p>

<p>Dies with &quot;QUITing...&quot; if WM_QUIT message is obtained.</p>

</dd>
<dt id="OS2::Process_Messages(force-[,-cnt])"><a class="permalink" href="perlos2.html#OS2::Process_Messages(force-%5B,-cnt%5D)">#</a><a id="OS26"></a><a id="OS2::Process_Messages-force-cnt"></a><code>OS2::Process_Messages(force [, cnt])</code></dt>
<dd>

<p>Retrieval of PM messages until window creation/destruction. If <code>force</code> is false, will not dispatch messages if a real message loop is known to be present.</p>

<p>Returns change in number of windows. If <code>cnt</code> is given, it is incremented by the number of messages retrieved.</p>

<p>Dies with &quot;QUITing...&quot; if WM_QUIT message is obtained.</p>

</dd>
<dt id="OS2::_control87(new,mask)"><a class="permalink" href="perlos2.html#OS2::_control87(new,mask)">#</a><a id="OS27"></a><a id="OS2::_control87-new-mask"></a><code>OS2::_control87(new,mask)</code></dt>
<dd>

<p>the same as <a href="http://man.he.net/man3/_control87">_control87(3)</a> of EMX. Takes integers as arguments, returns the previous coprocessor control word as an integer. Only bits in <code>new</code> which are present in <code>mask</code> are changed in the control word.</p>

</dd>
<dt id="OS2::get_control87()"><a class="permalink" href="perlos2.html#OS2::get_control87()">#</a><a id="OS28"></a><a id="OS2::get_control87"></a>OS2::get_control87()</dt>
<dd>

<p>gets the coprocessor control word as an integer.</p>

</dd>
<dt id="OS2::set_control87_em(new=MCW_EM,mask=MCW_EM)"><a class="permalink" href="perlos2.html#OS2::set_control87_em(new=MCW_EM,mask=MCW_EM)">#</a><a id="OS29"></a><a id="OS2::set_control87_em-new-MCW_EM-mask-MCW_EM"></a><code>OS2::set_control87_em(new=MCW_EM,mask=MCW_EM)</code></dt>
<dd>

<p>The variant of OS2::_control87() with default values good for handling exception mask: if no <code>mask</code>, uses exception mask part of <code>new</code> only. If no <code>new</code>, disables all the floating point exceptions.</p>

<p>See <a href="perlos2.html#Misfeatures">&quot;Misfeatures&quot;</a> for details.</p>

</dd>
<dt id="OS2::DLLname([how-[,-\&amp;xsub]])"><a class="permalink" href="perlos2.html#OS2::DLLname(%5Bhow-%5B,-%5C&amp;xsub%5D%5D)">#</a><a id="OS210"></a><a id="OS2::DLLname-how-xsub"></a><code>OS2::DLLname([how [, \&amp;xsub]])</code></dt>
<dd>

<p>Gives the information about the Perl DLL or the DLL containing the C function bound to by <code>&amp;xsub</code>. The meaning of <code>how</code> is: default (2): full name; 0: handle; 1: module name.</p>

</dd>
</dl>

<p>(Note that some of these may be moved to different libraries - eventually).</p>

<h2 id="Prebuilt-variables:"><a class="permalink" href="perlos2.html#Prebuilt-variables:">#</a><a id="Prebuilt1"></a><a id="Prebuilt-variables"></a>Prebuilt variables:</h2>

<dl>

<dt id="$OS2::emx_rev"><a class="permalink" href="perlos2.html#$OS2::emx_rev">#</a><a id="OS2::emx_rev"></a>$OS2::emx_rev</dt>
<dd>

<p>numeric value is the same as _emx_rev of EMX, a string value the same as _emx_vprt (similar to <code>0.9c</code>).</p>

</dd>
<dt id="$OS2::emx_env"><a class="permalink" href="perlos2.html#$OS2::emx_env">#</a><a id="OS2::emx_env"></a>$OS2::emx_env</dt>
<dd>

<p>same as _emx_env of EMX, a number similar to 0x8001.</p>

</dd>
<dt id="$OS2::os_ver"><a class="permalink" href="perlos2.html#$OS2::os_ver">#</a><a id="OS2::os_ver"></a>$OS2::os_ver</dt>
<dd>

<p>a number <code>OS_MAJOR + 0.001 * OS_MINOR</code>.</p>

</dd>
<dt id="$OS2::is_aout"><a class="permalink" href="perlos2.html#$OS2::is_aout">#</a><a id="OS2::is_aout"></a>$OS2::is_aout</dt>
<dd>

<p>true if the Perl library was compiled in AOUT format.</p>

</dd>
<dt id="$OS2::can_fork"><a class="permalink" href="perlos2.html#$OS2::can_fork">#</a><a id="OS2::can_fork"></a>$OS2::can_fork</dt>
<dd>

<p>true if the current executable is an AOUT EMX executable, so Perl can fork. Do not use this, use the portable check for $Config::Config{dfork}.</p>

</dd>
<dt id="$OS2::nsyserror"><a class="permalink" href="perlos2.html#$OS2::nsyserror">#</a><a id="OS2::nsyserror"></a>$OS2::nsyserror</dt>
<dd>

<p>This variable (default is 1) controls whether to enforce the contents of $^E to start with <code>SYS0003</code>-like id. If set to 0, then the string value of $^E is what is available from the OS/2 message file. (Some messages in this file have an <code>SYS0003</code>-like id prepended, some not.)</p>

</dd>
</dl>

<h2 id="Misfeatures"><a class="permalink" href="perlos2.html#Misfeatures">#</a>Misfeatures</h2>

<ul>

<li><p>Since <a href="http://man.he.net/man3/flock">flock(3)</a> is present in EMX, but is not functional, it is emulated by perl. To disable the emulations, set environment variable <code>USE_PERL_FLOCK=0</code>.</p>

</li>
<li><p>Here is the list of things which may be &quot;broken&quot; on EMX (from EMX docs):</p>

<ul>

<li><p>The functions <a href="http://man.he.net/man3/recvmsg">recvmsg(3)</a>, <a href="http://man.he.net/man3/sendmsg">sendmsg(3)</a>, and <a href="http://man.he.net/man3/socketpair">socketpair(3)</a> are not implemented.</p>

</li>
<li><p><a href="http://man.he.net/man3/sock_init">sock_init(3)</a> is not required and not implemented.</p>

</li>
<li><p><a href="http://man.he.net/man3/flock">flock(3)</a> is not yet implemented (dummy function). (Perl has a workaround.)</p>

</li>
<li><p><a href="http://man.he.net/man3/kill">kill(3)</a>: Special treatment of PID=0, PID=1 and PID=-1 is not implemented.</p>

</li>
<li><p><a href="http://man.he.net/man3/waitpid">waitpid(3)</a>:</p>

<pre><code class="plaintext">      WUNTRACED
	      Not implemented.
      waitpid() is not implemented for negative values of PID.</code></pre>

</li>
</ul>

<p>Note that <code>kill -9</code> does not work with the current version of EMX.</p>

</li>
<li><p>See <a href="perlos2.html#Text-mode-filehandles">&quot;Text-mode filehandles&quot;</a>.</p>

</li>
<li><p>Unix-domain sockets on OS/2 live in a pseudo-file-system <code>/sockets/...</code>. To avoid a failure to create a socket with a name of a different form, <code>&quot;/socket/&quot;</code> is prepended to the socket name (unless it starts with this already).</p>

<p>This may lead to problems later in case the socket is accessed via the &quot;usual&quot; file-system calls using the &quot;initial&quot; name.</p>

</li>
<li><p>Apparently, IBM used a compiler (for some period of time around &#39;95?) which changes FP mask right and left. This is not <i>that</i> bad for IBM&#39;s programs, but the same compiler was used for DLLs which are used with general-purpose applications. When these DLLs are used, the state of floating-point flags in the application is not predictable.</p>

<p>What is much worse, some DLLs change the floating point flags when in _DLLInitTerm() (e.g., <i>TCP32IP</i>). This means that even if you do not <i>call</i> any function in the DLL, just the act of loading this DLL will reset your flags. What is worse, the same compiler was used to compile some HOOK DLLs. Given that HOOK dlls are executed in the context of <i>all</i> the applications in the system, this means a complete unpredictability of floating point flags on systems using such HOOK DLLs. E.g., <i>GAMESRVR.DLL</i> of <b>DIVE</b> origin changes the floating point flags on each write to the TTY of a VIO (windowed text-mode) applications.</p>

<p>Some other (not completely debugged) situations when FP flags change include some video drivers (?), and some operations related to creation of the windows. People who code <b>OpenGL</b> may have more experience on this.</p>

<p>Perl is generally used in the situation when all the floating-point exceptions are ignored, as is the default under EMX. If they are not ignored, some benign Perl programs would get a <code>SIGFPE</code> and would die a horrible death.</p>

<p>To circumvent this, Perl uses two hacks. They help against <i>one</i> type of damage only: FP flags changed when loading a DLL.</p>

<p>One of the hacks is to disable floating point exceptions on Perl startup (as is the default with EMX). This helps only with compile-time-linked DLLs changing the flags before main() had a chance to be called.</p>

<p>The other hack is to restore FP flags after a call to dlopen(). This helps against similar damage done by DLLs _DLLInitTerm() at runtime. Currently no way to switch these hacks off is provided.</p>

</li>
</ul>

<h2 id="Modifications"><a class="permalink" href="perlos2.html#Modifications">#</a>Modifications</h2>

<p>Perl modifies some standard C library calls in the following ways:</p>

<dl>

<dt id="popen"><a class="permalink" href="perlos2.html#popen">#</a><code>popen</code></dt>
<dd>

<p><code>my_popen</code> uses <i>sh.exe</i> if shell is required, cf. <a href="perlos2.html#PERL_SH_DIR">&quot;<code>PERL_SH_DIR</code>&quot;</a>.</p>

</dd>
<dt id="tmpnam"><a class="permalink" href="perlos2.html#tmpnam">#</a><code>tmpnam</code></dt>
<dd>

<p>is created using <code>TMP</code> or <code>TEMP</code> environment variable, via <code>tempnam</code>.</p>

</dd>
<dt id="tmpfile"><a class="permalink" href="perlos2.html#tmpfile">#</a><code>tmpfile</code></dt>
<dd>

<p>If the current directory is not writable, file is created using modified <code>tmpnam</code>, so there may be a race condition.</p>

</dd>
<dt id="ctermid"><a class="permalink" href="perlos2.html#ctermid">#</a><code>ctermid</code></dt>
<dd>

<p>a dummy implementation.</p>

</dd>
<dt id="stat"><a class="permalink" href="perlos2.html#stat">#</a><code>stat</code></dt>
<dd>

<p><code>os2_stat</code> special-cases <i>/dev/tty</i> and <i>/dev/con</i>.</p>

</dd>
<dt id="mkdir,-rmdir"><a class="permalink" href="perlos2.html#mkdir,-rmdir">#</a><a id="mkdir"></a><a id="mkdir-rmdir"></a><code>mkdir</code>, <code>rmdir</code></dt>
<dd>

<p>these EMX functions do not work if the path contains a trailing <code>/</code>. Perl contains a workaround for this.</p>

</dd>
<dt id="flock"><a class="permalink" href="perlos2.html#flock">#</a><code>flock</code></dt>
<dd>

<p>Since <a href="http://man.he.net/man3/flock">flock(3)</a> is present in EMX, but is not functional, it is emulated by perl. To disable the emulations, set environment variable <code>USE_PERL_FLOCK=0</code>.</p>

</dd>
</dl>

<h2 id="Identifying-DLLs"><a class="permalink" href="perlos2.html#Identifying-DLLs">#</a><a id="Identifying"></a>Identifying DLLs</h2>

<p>All the DLLs built with the current versions of Perl have ID strings identifying the name of the extension, its version, and the version of Perl required for this DLL. Run <code>bldlevel DLL-name</code> to find this info.</p>

<h2 id="Centralized-management-of-resources"><a class="permalink" href="perlos2.html#Centralized-management-of-resources">#</a><a id="Centralized"></a>Centralized management of resources</h2>

<p>Since to call certain OS/2 API one needs to have a correctly initialized <code>Win</code> subsystem, OS/2-specific extensions may require getting <code>HAB</code>s and <code>HMQ</code>s. If an extension would do it on its own, another extension could fail to initialize.</p>

<p>Perl provides a centralized management of these resources:</p>

<dl>

<dt id="HAB"><a class="permalink" href="perlos2.html#HAB">#</a><code>HAB</code></dt>
<dd>

<p>To get the HAB, the extension should call <code>hab = perl_hab_GET()</code> in C. After this call is performed, <code>hab</code> may be accessed as <code>Perl_hab</code>. There is no need to release the HAB after it is used.</p>

<p>If by some reasons <i>perl.h</i> cannot be included, use</p>

<pre><code>extern int Perl_hab_GET(void);</code></pre>

<p>instead.</p>

</dd>
<dt id="HMQ"><a class="permalink" href="perlos2.html#HMQ">#</a><code>HMQ</code></dt>
<dd>

<p>There are two cases:</p>

<ul>

<li><p>the extension needs an <code>HMQ</code> only because some API will not work otherwise. Use <code>serve = 0</code> below.</p>

</li>
<li><p>the extension needs an <code>HMQ</code> since it wants to engage in a PM event loop. Use <code>serve = 1</code> below.</p>

</li>
</ul>

<p>To get an <code>HMQ</code>, the extension should call <code>hmq = perl_hmq_GET(serve)</code> in C. After this call is performed, <code>hmq</code> may be accessed as <code>Perl_hmq</code>.</p>

<p>To signal to Perl that HMQ is not needed any more, call <code>perl_hmq_UNSET(serve)</code>. Perl process will automatically morph/unmorph itself into/from a PM process if HMQ is needed/not-needed. Perl will automatically enable/disable <code>WM_QUIT</code> message during shutdown if the message queue is served/not-served.</p>

<p><b>NOTE</b>. If during a shutdown there is a message queue which did not disable WM_QUIT, and which did not process the received WM_QUIT message, the shutdown will be automatically cancelled. Do not call <code>perl_hmq_GET(1)</code> unless you are going to process messages on an orderly basis.</p>

</dd>
<dt id="Treating-errors-reported-by-OS/2-API"><a class="permalink" href="perlos2.html#Treating-errors-reported-by-OS/2-API">#</a><a id="Treating"></a><a id="Treating-errors-reported-by-OS-2-API"></a>Treating errors reported by OS/2 API</dt>
<dd>

<p>There are two principal conventions (it is useful to call them <code>Dos*</code> and <code>Win*</code> - though this part of the function signature is not always determined by the name of the API) of reporting the error conditions of OS/2 API. Most of <code>Dos*</code> APIs report the error code as the result of the call (so 0 means success, and there are many types of errors). Most of <code>Win*</code> API report success/fail via the result being <code>TRUE</code>/<code>FALSE</code>; to find the reason for the failure one should call WinGetLastError() API.</p>

<p>Some <code>Win*</code> entry points also overload a &quot;meaningful&quot; return value with the error indicator; having a 0 return value indicates an error. Yet some other <code>Win*</code> entry points overload things even more, and 0 return value may mean a successful call returning a valid value 0, as well as an error condition; in the case of a 0 return value one should call WinGetLastError() API to distinguish a successful call from a failing one.</p>

<p>By convention, all the calls to OS/2 API should indicate their failures by resetting $^E. All the Perl-accessible functions which call OS/2 API may be broken into two classes: some die()s when an API error is encountered, the other report the error via a false return value (of course, this does not concern Perl-accessible functions which <i>expect</i> a failure of the OS/2 API call, having some workarounds coded).</p>

<p>Obviously, in the situation of the last type of the signature of an OS/2 API, it is must more convenient for the users if the failure is indicated by die()ing: one does not need to check $^E to know that something went wrong. If, however, this solution is not desirable by some reason, the code in question should reset $^E to 0 before making this OS/2 API call, so that the caller of this Perl-accessible function has a chance to distinguish a success-but-0-return value from a failure. (One may return undef as an alternative way of reporting an error.)</p>

<p>The macros to simplify this type of error propagation are</p>

<dl>

<dt id="CheckOSError(expr)"><a class="permalink" href="perlos2.html#CheckOSError(expr)">#</a><a id="CheckOSError"></a><a id="CheckOSError-expr"></a><code>CheckOSError(expr)</code></dt>
<dd>

<p>Returns true on error, sets $^E. Expects expr() be a call of <code>Dos*</code>-style API.</p>

</dd>
<dt id="CheckWinError(expr)"><a class="permalink" href="perlos2.html#CheckWinError(expr)">#</a><a id="CheckWinError"></a><a id="CheckWinError-expr"></a><code>CheckWinError(expr)</code></dt>
<dd>

<p>Returns true on error, sets $^E. Expects expr() be a call of <code>Win*</code>-style API.</p>

</dd>
<dt id="SaveWinError(expr)"><a class="permalink" href="perlos2.html#SaveWinError(expr)">#</a><a id="SaveWinError"></a><a id="SaveWinError-expr"></a><code>SaveWinError(expr)</code></dt>
<dd>

<p>Returns <code>expr</code>, sets $^E from WinGetLastError() if <code>expr</code> is false.</p>

</dd>
<dt id="SaveCroakWinError(expr,die,name1,name2)"><a class="permalink" href="perlos2.html#SaveCroakWinError(expr,die,name1,name2)">#</a><a id="SaveCroakWinError"></a><a id="SaveCroakWinError-expr-die-name1-name2"></a><code>SaveCroakWinError(expr,die,name1,name2)</code></dt>
<dd>

<p>Returns <code>expr</code>, sets $^E from WinGetLastError() if <code>expr</code> is false, and die()s if <code>die</code> and $^E are true. The message to die is the concatenated strings <code>name1</code> and <code>name2</code>, separated by <code>&quot;: &quot;</code> from the contents of $^E.</p>

</dd>
<dt id="WinError_2_Perl_rc"><a class="permalink" href="perlos2.html#WinError_2_Perl_rc">#</a><code>WinError_2_Perl_rc</code></dt>
<dd>

<p>Sets <code>Perl_rc</code> to the return value of WinGetLastError().</p>

</dd>
<dt id="FillWinError"><a class="permalink" href="perlos2.html#FillWinError">#</a><code>FillWinError</code></dt>
<dd>

<p>Sets <code>Perl_rc</code> to the return value of WinGetLastError(), and sets $^E to the corresponding value.</p>

</dd>
<dt id="FillOSError(rc)"><a class="permalink" href="perlos2.html#FillOSError(rc)">#</a><a id="FillOSError"></a><a id="FillOSError-rc"></a><code>FillOSError(rc)</code></dt>
<dd>

<p>Sets <code>Perl_rc</code> to <code>rc</code>, and sets $^E to the corresponding value.</p>

</dd>
</dl>

</dd>
<dt id="Loading-DLLs-and-ordinals-in-DLLs"><a class="permalink" href="perlos2.html#Loading-DLLs-and-ordinals-in-DLLs">#</a><a id="Loading"></a>Loading DLLs and ordinals in DLLs</dt>
<dd>

<p>Some DLLs are only present in some versions of OS/2, or in some configurations of OS/2. Some exported entry points are present only in DLLs shipped with some versions of OS/2. If these DLLs and entry points were linked directly for a Perl executable/DLL or from a Perl extensions, this binary would work only with the specified versions/setups. Even if these entry points were not needed, the <i>load</i> of the executable (or DLL) would fail.</p>

<p>For example, many newer useful APIs are not present in OS/2 v2; many PM-related APIs require DLLs not available on floppy-boot setup.</p>

<p>To make these calls fail <i>only when the calls are executed</i>, one should call these API via a dynamic linking API. There is a subsystem in Perl to simplify such type of calls. A large number of entry points available for such linking is provided (see <code>entries_ordinals</code> - and also <code>PMWIN_entries</code> - in <i>os2ish.h</i>). These ordinals can be accessed via the APIs:</p>

<pre><code class="plaintext">CallORD(), DeclFuncByORD(), DeclVoidFuncByORD(),
DeclOSFuncByORD(), DeclWinFuncByORD(), AssignFuncPByORD(),
DeclWinFuncByORD_CACHE(), DeclWinFuncByORD_CACHE_survive(),
DeclWinFuncByORD_CACHE_resetError_survive(),
DeclWinFunc_CACHE(), DeclWinFunc_CACHE_resetError(),
DeclWinFunc_CACHE_survive(), DeclWinFunc_CACHE_resetError_survive()</code></pre>

<p>See the header files and the C code in the supplied OS/2-related modules for the details on usage of these functions.</p>

<p>Some of these functions also combine dynaloading semantic with the error-propagation semantic discussed above.</p>

</dd>
</dl>

<h1 id="Perl-flavors"><a class="permalink" href="perlos2.html#Perl-flavors">#</a><a id="Perl2"></a>Perl flavors</h1>

<p>Because of idiosyncrasies of OS/2 one cannot have all the eggs in the same basket (though EMX environment tries hard to overcome this limitations, so the situation may somehow improve). There are 4 executables for Perl provided by the distribution:</p>

<h2 id="perl.exe"><a class="permalink" href="perlos2.html#perl.exe">#</a><a id="perl"></a><i>perl.exe</i></h2>

<p>The main workhorse. This is a chimera executable: it is compiled as an <code>a.out</code>-style executable, but is linked with <code>omf</code>-style dynamic library <i>perl.dll</i>, and with dynamic CRT DLL. This executable is a VIO application.</p>

<p>It can load perl dynamic extensions, and it can fork().</p>

<p><b>Note.</b> Keep in mind that fork() is needed to open a pipe to yourself.</p>

<h2 id="perl_.exe"><a class="permalink" href="perlos2.html#perl_.exe">#</a><a id="perl_"></a><i>perl_.exe</i></h2>

<p>This is a statically linked <code>a.out</code>-style executable. It cannot load dynamic Perl extensions. The executable supplied in binary distributions has a lot of extensions prebuilt, thus the above restriction is important only if you use custom-built extensions. This executable is a VIO application.</p>

<p><i>This is the only executable with does not require OS/2.</i> The friends locked into <code>M$</code> world would appreciate the fact that this executable runs under DOS, Win0.3*, Win0.95 and WinNT with an appropriate extender. See <a href="perlos2.html#Other-OSes">&quot;Other OSes&quot;</a>.</p>

<h2 id="perl__.exe"><a class="permalink" href="perlos2.html#perl__.exe">#</a><a id="perl__"></a><i>perl__.exe</i></h2>

<p>This is the same executable as <i>perl___.exe</i>, but it is a PM application.</p>

<p><b>Note.</b> Usually (unless explicitly redirected during the startup) STDIN, STDERR, and STDOUT of a PM application are redirected to <i>nul</i>. However, it is possible to <i>see</i> them if you start <code>perl__.exe</code> from a PM program which emulates a console window, like <i>Shell mode</i> of Emacs or EPM. Thus it <i>is possible</i> to use Perl debugger (see <a href="perldebug.html">perldebug</a>) to debug your PM application (but beware of the message loop lockups - this will not work if you have a message queue to serve, unless you hook the serving into the getc() function of the debugger).</p>

<p>Another way to see the output of a PM program is to run it as</p>

<pre><code class="plaintext">pm_prog args 2&gt;&amp;1 | cat -</code></pre>

<p>with a shell <i>different</i> from <i>cmd.exe</i>, so that it does not create a link between a VIO session and the session of <code>pm_porg</code>. (Such a link closes the VIO window.) E.g., this works with <i>sh.exe</i> - or with Perl!</p>

<pre><code>open P, &#39;pm_prog args 2&gt;&amp;1 |&#39; or die;
print while &lt;P&gt;;</code></pre>

<p>The flavor <i>perl__.exe</i> is required if you want to start your program without a VIO window present, but not <code>detach</code>ed (run <code>help detach</code> for more info). Very useful for extensions which use PM, like <code>Perl/Tk</code> or <code>OpenGL</code>.</p>

<p>Note also that the differences between PM and VIO executables are only in the <i>default</i> behaviour. One can start <i>any</i> executable in <i>any</i> kind of session by using the arguments <code>/fs</code>, <code>/pm</code> or <code>/win</code> switches of the command <code>start</code> (of <i>CMD.EXE</i> or a similar shell). Alternatively, one can use the numeric first argument of the <code>system</code> Perl function (see <a href="./OS2::Process.html">OS2::Process</a>).</p>

<h2 id="perl___.exe"><a class="permalink" href="perlos2.html#perl___.exe">#</a><a id="perl___"></a><i>perl___.exe</i></h2>

<p>This is an <code>omf</code>-style executable which is dynamically linked to <i>perl.dll</i> and CRT DLL. I know no advantages of this executable over <code>perl.exe</code>, but it cannot fork() at all. Well, one advantage is that the build process is not so convoluted as with <code>perl.exe</code>.</p>

<p>It is a VIO application.</p>

<h2 id="Why-strange-names?"><a class="permalink" href="perlos2.html#Why-strange-names?">#</a><a id="Why"></a><a id="Why-strange-names"></a>Why strange names?</h2>

<p>Since Perl processes the <code>#!</code>-line (cf. <a href="perlrun.html#DESCRIPTION">&quot;DESCRIPTION&quot; in perlrun</a>, <a href="perlrun.html#Command-Switches">&quot;Command Switches&quot; in perlrun</a>, <a href="perldiag.html#No-Perl-script-found-in-input">&quot;No Perl script found in input&quot; in perldiag</a>), it should know when a program <i>is a Perl</i>. There is some naming convention which allows Perl to distinguish correct lines from wrong ones. The above names are almost the only names allowed by this convention which do not contain digits (which have absolutely different semantics).</p>

<h2 id="Why-dynamic-linking?"><a class="permalink" href="perlos2.html#Why-dynamic-linking?">#</a><a id="Why1"></a><a id="Why-dynamic-linking"></a>Why dynamic linking?</h2>

<p>Well, having several executables dynamically linked to the same huge library has its advantages, but this would not substantiate the additional work to make it compile. The reason is the complicated-to-developers but very quick and convenient-to-users &quot;hard&quot; dynamic linking used by OS/2.</p>

<p>There are two distinctive features of the dyna-linking model of OS/2: first, all the references to external functions are resolved at the compile time; second, there is no runtime fixup of the DLLs after they are loaded into memory. The first feature is an enormous advantage over other models: it avoids conflicts when several DLLs used by an application export entries with the same name. In such cases &quot;other&quot; models of dyna-linking just choose between these two entry points using some random criterion - with predictable disasters as results. But it is the second feature which requires the build of <i>perl.dll</i>.</p>

<p>The address tables of DLLs are patched only once, when they are loaded. The addresses of the entry points into DLLs are guaranteed to be the same for all the programs which use the same DLL. This removes the runtime fixup - once DLL is loaded, its code is read-only.</p>

<p>While this allows some (significant?) performance advantages, this makes life much harder for developers, since the above scheme makes it impossible for a DLL to be &quot;linked&quot; to a symbol in the <i>.EXE</i> file. Indeed, this would need a DLL to have different relocations tables for the (different) executables which use this DLL.</p>

<p>However, a dynamically loaded Perl extension is forced to use some symbols from the perl executable, e.g., to know how to find the arguments to the functions: the arguments live on the perl internal evaluation stack. The solution is to put the main code of the interpreter into a DLL, and make the <i>.EXE</i> file which just loads this DLL into memory and supplies command-arguments. The extension DLL cannot link to symbols in <i>.EXE</i>, but it has no problem linking to symbols in the <i>.DLL</i>.</p>

<p>This <i>greatly</i> increases the load time for the application (as well as complexity of the compilation). Since interpreter is in a DLL, the C RTL is basically forced to reside in a DLL as well (otherwise extensions would not be able to use CRT). There are some advantages if you use different flavors of perl, such as running <i>perl.exe</i> and <i>perl__.exe</i> simultaneously: they share the memory of <i>perl.dll</i>.</p>

<p><b>NOTE</b>. There is one additional effect which makes DLLs more wasteful: DLLs are loaded in the shared memory region, which is a scarse resource given the 512M barrier of the &quot;standard&quot; OS/2 virtual memory. The code of <i>.EXE</i> files is also shared by all the processes which use the particular <i>.EXE</i>, but they are &quot;shared in the private address space of the process&quot;; this is possible because the address at which different sections of the <i>.EXE</i> file are loaded is decided at compile-time, thus all the processes have these sections loaded at same addresses, and no fixup of internal links inside the <i>.EXE</i> is needed.</p>

<p>Since DLLs may be loaded at run time, to have the same mechanism for DLLs one needs to have the address range of <i>any of the loaded</i> DLLs in the system to be available <i>in all the processes</i> which did not load a particular DLL yet. This is why the DLLs are mapped to the shared memory region.</p>

<h2 id="Why-chimera-build?"><a class="permalink" href="perlos2.html#Why-chimera-build?">#</a><a id="Why2"></a><a id="Why-chimera-build"></a>Why chimera build?</h2>

<p>Current EMX environment does not allow DLLs compiled using Unixish <code>a.out</code> format to export symbols for data (or at least some types of data). This forces <code>omf</code>-style compile of <i>perl.dll</i>.</p>

<p>Current EMX environment does not allow <i>.EXE</i> files compiled in <code>omf</code> format to fork(). fork() is needed for exactly three Perl operations:</p>

<ul>

<li><p>explicit fork() in the script,</p>

</li>
<li><p><code>open FH, &quot;|-&quot;</code></p>

</li>
<li><p><code>open FH, &quot;-|&quot;</code>, in other words, opening pipes to itself.</p>

</li>
</ul>

<p>While these operations are not questions of life and death, they are needed for a lot of useful scripts. This forces <code>a.out</code>-style compile of <i>perl.exe</i>.</p>

<h1 id="ENVIRONMENT"><a class="permalink" href="perlos2.html#ENVIRONMENT">#</a>ENVIRONMENT</h1>

<p>Here we list environment variables with are either OS/2- and DOS- and Win*-specific, or are more important under OS/2 than under other OSes.</p>

<h2 id="PERLLIB_PREFIX"><a class="permalink" href="perlos2.html#PERLLIB_PREFIX">#</a><code>PERLLIB_PREFIX</code></h2>

<p>Specific for EMX port. Should have the form</p>

<pre><code class="plaintext">path1;path2</code></pre>

<p>or</p>

<pre><code class="plaintext">path1 path2</code></pre>

<p>If the beginning of some prebuilt path matches <i>path1</i>, it is substituted with <i>path2</i>.</p>

<p>Should be used if the perl library is moved from the default location in preference to <code>PERL(5)LIB</code>, since this would not leave wrong entries in @INC. For example, if the compiled version of perl looks for @INC in <i>f:/perllib/lib</i>, and you want to install the library in <i>h:/opt/gnu</i>, do</p>

<pre><code class="plaintext">set PERLLIB_PREFIX=f:/perllib/lib;h:/opt/gnu</code></pre>

<p>This will cause Perl with the prebuilt @INC of</p>

<pre><code class="plaintext">f:/perllib/lib/5.00553/os2
f:/perllib/lib/5.00553
f:/perllib/lib/site_perl/5.00553/os2
f:/perllib/lib/site_perl/5.00553
.</code></pre>

<p>to use the following @INC:</p>

<pre><code class="plaintext">h:/opt/gnu/5.00553/os2
h:/opt/gnu/5.00553
h:/opt/gnu/site_perl/5.00553/os2
h:/opt/gnu/site_perl/5.00553
.</code></pre>

<h2 id="PERL_BADLANG1"><a class="permalink" href="perlos2.html#PERL_BADLANG1">#</a><code>PERL_BADLANG</code></h2>

<p>If 0, perl ignores setlocale() failing. May be useful with some strange <i>locale</i>s.</p>

<h2 id="PERL_BADFREE1"><a class="permalink" href="perlos2.html#PERL_BADFREE1">#</a><code>PERL_BADFREE</code></h2>

<p>If 0, perl would not warn of in case of unwarranted free(). With older perls this might be useful in conjunction with the module DB_File, which was buggy when dynamically linked and OMF-built.</p>

<p>Should not be set with newer Perls, since this may hide some <i>real</i> problems.</p>

<h2 id="PERL_SH_DIR"><a class="permalink" href="perlos2.html#PERL_SH_DIR">#</a><code>PERL_SH_DIR</code></h2>

<p>Specific for EMX port. Gives the directory part of the location for <i>sh.exe</i>.</p>

<h2 id="USE_PERL_FLOCK"><a class="permalink" href="perlos2.html#USE_PERL_FLOCK">#</a><code>USE_PERL_FLOCK</code></h2>

<p>Specific for EMX port. Since <a href="http://man.he.net/man3/flock">flock(3)</a> is present in EMX, but is not functional, it is emulated by perl. To disable the emulations, set environment variable <code>USE_PERL_FLOCK=0</code>.</p>

<h2 id="TMP-or-TEMP"><a class="permalink" href="perlos2.html#TMP-or-TEMP">#</a><a id="TMP"></a><code>TMP</code> or <code>TEMP</code></h2>

<p>Specific for EMX port. Used as storage place for temporary files.</p>

<h1 id="Evolution"><a class="permalink" href="perlos2.html#Evolution">#</a>Evolution</h1>

<p>Here we list major changes which could make you by surprise.</p>

<h2 id="Text-mode-filehandles"><a class="permalink" href="perlos2.html#Text-mode-filehandles">#</a><a id="Text"></a>Text-mode filehandles</h2>

<p>Starting from version 5.8, Perl uses a builtin translation layer for text-mode files. This replaces the efficient well-tested EMX layer by some code which should be best characterized as a &quot;quick hack&quot;.</p>

<p>In addition to possible bugs and an inability to follow changes to the translation policy with off/on switches of TERMIO translation, this introduces a serious incompatible change: before sysread() on text-mode filehandles would go through the translation layer, now it would not.</p>

<h2 id="Priorities"><a class="permalink" href="perlos2.html#Priorities">#</a>Priorities</h2>

<p><code>setpriority</code> and <code>getpriority</code> are not compatible with earlier ports by Andreas Kaiser. See <code>&quot;setpriority, getpriority&quot;</code>.</p>

<h2 id="DLL-name-mangling:-pre-5.6.2"><a class="permalink" href="perlos2.html#DLL-name-mangling:-pre-5.6.2">#</a><a id="DLL"></a>DLL name mangling: pre 5.6.2</h2>

<p>With the release 5.003_01 the dynamically loadable libraries should be rebuilt when a different version of Perl is compiled. In particular, DLLs (including <i>perl.dll</i>) are now created with the names which contain a checksum, thus allowing workaround for OS/2 scheme of caching DLLs.</p>

<p>It may be possible to code a simple workaround which would</p>

<ul>

<li><p>find the old DLLs looking through the old @INC;</p>

</li>
<li><p>mangle the names according to the scheme of new perl and copy the DLLs to these names;</p>

</li>
<li><p>edit the internal <code>LX</code> tables of DLL to reflect the change of the name (probably not needed for Perl extension DLLs, since the internally coded names are not used for &quot;specific&quot; DLLs, they used only for &quot;global&quot; DLLs).</p>

</li>
<li><p>edit the internal <code>IMPORT</code> tables and change the name of the &quot;old&quot; <i>perl????.dll</i> to the &quot;new&quot; <i>perl????.dll</i>.</p>

</li>
</ul>

<h2 id="DLL-name-mangling:-5.6.2-and-beyond"><a class="permalink" href="perlos2.html#DLL-name-mangling:-5.6.2-and-beyond">#</a><a id="DLL1"></a>DLL name mangling: 5.6.2 and beyond</h2>

<p>In fact mangling of <i>extension</i> DLLs was done due to misunderstanding of the OS/2 dynaloading model. OS/2 (effectively) maintains two different tables of loaded DLL:</p>

<dl>

<dt id="Global-DLLs"><a class="permalink" href="perlos2.html#Global-DLLs">#</a><a id="Global"></a>Global DLLs</dt>
<dd>

<p>those loaded by the base name from <code>LIBPATH</code>; including those associated at link time;</p>

</dd>
<dt id="specific-DLLs"><a class="permalink" href="perlos2.html#specific-DLLs">#</a><a id="specific"></a>specific DLLs</dt>
<dd>

<p>loaded by the full name.</p>

</dd>
</dl>

<p>When resolving a request for a global DLL, the table of already-loaded specific DLLs is (effectively) ignored; moreover, specific DLLs are <i>always</i> loaded from the prescribed path.</p>

<p>There is/was a minor twist which makes this scheme fragile: what to do with DLLs loaded from</p>

<dl>

<dt id="BEGINLIBPATH-and-ENDLIBPATH"><a class="permalink" href="perlos2.html#BEGINLIBPATH-and-ENDLIBPATH">#</a><a id="BEGINLIBPATH"></a><code>BEGINLIBPATH</code> and <code>ENDLIBPATH</code></dt>
<dd>

<p>(which depend on the process)</p>

</dd>
<dt id=".-from-LIBPATH"><a class="permalink" href="perlos2.html#.-from-LIBPATH">#</a><a id="from-LIBPATH"></a><i>.</i> from <code>LIBPATH</code></dt>
<dd>

<p>which <i>effectively</i> depends on the process (although <code>LIBPATH</code> is the same for all the processes).</p>

</dd>
</dl>

<p>Unless <code>LIBPATHSTRICT</code> is set to <code>T</code> (and the kernel is after 2000/09/01), such DLLs are considered to be global. When loading a global DLL it is first looked in the table of already-loaded global DLLs. Because of this the fact that one executable loaded a DLL from <code>BEGINLIBPATH</code> and <code>ENDLIBPATH</code>, or <i>.</i> from <code>LIBPATH</code> may affect <i>which</i> DLL is loaded when <i>another</i> executable requests a DLL with the same name. <i>This</i> is the reason for version-specific mangling of the DLL name for perl DLL.</p>

<p>Since the Perl extension DLLs are always loaded with the full path, there is no need to mangle their names in a version-specific ways: their directory already reflects the corresponding version of perl, and @INC takes into account binary compatibility with older version. Starting from <code>5.6.2</code> the name mangling scheme is fixed to be the same as for Perl 5.005_53 (same as in a popular binary release). Thus new Perls will be able to <i>resolve the names</i> of old extension DLLs if @INC allows finding their directories.</p>

<p>However, this still does not guarantee that these DLL may be loaded. The reason is the mangling of the name of the <i>Perl DLL</i>. And since the extension DLLs link with the Perl DLL, extension DLLs for older versions would load an older Perl DLL, and would most probably segfault (since the data in this DLL is not properly initialized).</p>

<p>There is a partial workaround (which can be made complete with newer OS/2 kernels): create a forwarder DLL with the same name as the DLL of the older version of Perl, which forwards the entry points to the newer Perl&#39;s DLL. Make this DLL accessible on (say) the <code>BEGINLIBPATH</code> of the new Perl executable. When the new executable accesses old Perl&#39;s extension DLLs, they would request the old Perl&#39;s DLL by name, get the forwarder instead, so effectively will link with the currently running (new) Perl DLL.</p>

<p>This may break in two ways:</p>

<ul>

<li><p>Old perl executable is started when a new executable is running has loaded an extension compiled for the old executable (ouph!). In this case the old executable will get a forwarder DLL instead of the old perl DLL, so would link with the new perl DLL. While not directly fatal, it will behave the same as new executable. This beats the whole purpose of explicitly starting an old executable.</p>

</li>
<li><p>A new executable loads an extension compiled for the old executable when an old perl executable is running. In this case the extension will not pick up the forwarder - with fatal results.</p>

</li>
</ul>

<p>With support for <code>LIBPATHSTRICT</code> this may be circumvented - unless one of DLLs is started from <i>.</i> from <code>LIBPATH</code> (I do not know whether <code>LIBPATHSTRICT</code> affects this case).</p>

<p><b>REMARK</b>. Unless newer kernels allow <i>.</i> in <code>BEGINLIBPATH</code> (older do not), this mess cannot be completely cleaned. (It turns out that as of the beginning of 2002, <i>.</i> is not allowed, but <i>.\.</i> is - and it has the same effect.)</p>

<p><b>REMARK</b>. <code>LIBPATHSTRICT</code>, <code>BEGINLIBPATH</code> and <code>ENDLIBPATH</code> are not environment variables, although <i>cmd.exe</i> emulates them on <code>SET ...</code> lines. From Perl they may be accessed by <a href="perlos2.html#Cwd%3A%3AextLibpath%28%5Btype%5D%29">Cwd::extLibpath</a> and <a href="perlos2.html#Cwd%3A%3AextLibpath_set%28-path-%5B%2C-type-%5D-%29">Cwd::extLibpath_set</a>.</p>

<h2 id="DLL-forwarder-generation"><a class="permalink" href="perlos2.html#DLL-forwarder-generation">#</a><a id="DLL2"></a>DLL forwarder generation</h2>

<p>Assume that the old DLL is named <i>perlE0AC.dll</i> (as is one for 5.005_53), and the new version is 5.6.1. Create a file <i>perl5shim.def-leader</i> with</p>

<pre><code>LIBRARY &#39;perlE0AC&#39; INITINSTANCE TERMINSTANCE
DESCRIPTION &#39;@#perl5-porters@perl.org:5.006001#@ Perl module for 5.00553 -&gt; Perl 5.6.1 forwarder&#39;
CODE LOADONCALL
DATA LOADONCALL NONSHARED MULTIPLE
EXPORTS</code></pre>

<p>modifying the versions/names as needed. Run</p>

<pre><code>perl -wnle &quot;next if 0../EXPORTS/; print qq(  \&quot;$1\&quot;)
                                         if /\&quot;(\w+)\&quot;/&quot; perl5.def &gt;lst</code></pre>

<p>in the Perl build directory (to make the DLL smaller replace perl5.def with the definition file for the older version of Perl if present).</p>

<pre><code class="plaintext">cat perl5shim.def-leader lst &gt;perl5shim.def
gcc -Zomf -Zdll -o perlE0AC.dll perl5shim.def -s -llibperl</code></pre>

<p>(ignore multiple <code>warning L4085</code>).</p>

<h2 id="Threading"><a class="permalink" href="perlos2.html#Threading">#</a>Threading</h2>

<p>As of release 5.003_01 perl is linked to multithreaded C RTL DLL. If perl itself is not compiled multithread-enabled, so will not be perl&#39;s malloc(). However, extensions may use multiple thread on their own risk.</p>

<p>This was needed to compile <code>Perl/Tk</code> for XFree86-OS/2 out-of-the-box, and link with DLLs for other useful libraries, which typically are compiled with <code>-Zmt -Zcrtdll</code>.</p>

<h2 id="Calls-to-external-programs"><a class="permalink" href="perlos2.html#Calls-to-external-programs">#</a><a id="Calls"></a>Calls to external programs</h2>

<p>Due to a popular demand the perl external program calling has been changed wrt Andreas Kaiser&#39;s port. <i>If</i> perl needs to call an external program <i>via shell</i>, the <i>f:/bin/sh.exe</i> will be called, or whatever is the override, see <a href="perlos2.html#PERL_SH_DIR">&quot;<code>PERL_SH_DIR</code>&quot;</a>.</p>

<p>Thus means that you need to get some copy of a <i>sh.exe</i> as well (I use one from pdksh). The path <i>F:/bin</i> above is set up automatically during the build to a correct value on the builder machine, but is overridable at runtime,</p>

<p><b>Reasons:</b> a consensus on <code>perl5-porters</code> was that perl should use one non-overridable shell per platform. The obvious choices for OS/2 are <i>cmd.exe</i> and <i>sh.exe</i>. Having perl build itself would be impossible with <i>cmd.exe</i> as a shell, thus I picked up <code>sh.exe</code>. This assures almost 100% compatibility with the scripts coming from *nix. As an added benefit this works as well under DOS if you use DOS-enabled port of pdksh (see <a href="perlos2.html#Prerequisites">&quot;Prerequisites&quot;</a>).</p>

<p><b>Disadvantages:</b> currently <i>sh.exe</i> of pdksh calls external programs via fork()/exec(), and there is <i>no</i> functioning exec() on OS/2. exec() is emulated by EMX by an asynchronous call while the caller waits for child completion (to pretend that the <code>pid</code> did not change). This means that 1 <i>extra</i> copy of <i>sh.exe</i> is made active via fork()/exec(), which may lead to some resources taken from the system (even if we do not count extra work needed for fork()ing).</p>

<p>Note that this a lesser issue now when we do not spawn <i>sh.exe</i> unless needed (metachars found).</p>

<p>One can always start <i>cmd.exe</i> explicitly via</p>

<pre><code class="plaintext">system &#39;cmd&#39;, &#39;/c&#39;, &#39;mycmd&#39;, &#39;arg1&#39;, &#39;arg2&#39;, ...</code></pre>

<p>If you need to use <i>cmd.exe</i>, and do not want to hand-edit thousands of your scripts, the long-term solution proposed on p5-p is to have a directive</p>

<pre><code>use OS2::Cmd;</code></pre>

<p>which will override system(), exec(), <code>``</code>, and <code>open(,&#39;...|&#39;)</code>. With current perl you may override only system(), readpipe() - the explicit version of <code>``</code>, and maybe exec(). The code will substitute the one-argument call to system() by <code>CORE::system(&#39;cmd.exe&#39;, &#39;/c&#39;, shift)</code>.</p>

<p>If you have some working code for <code>OS2::Cmd</code>, please send it to me, I will include it into distribution. I have no need for such a module, so cannot test it.</p>

<p>For the details of the current situation with calling external programs, see <a href="perlos2.html#Starting-OS%2F2-%28and-DOS%29-programs-under-Perl">&quot;Starting OS/2 (and DOS) programs under Perl&quot;</a>. Set us mention a couple of features:</p>

<ul>

<li><p>External scripts may be called by their basename. Perl will try the same extensions as when processing <b>-S</b> command-line switch.</p>

</li>
<li><p>External scripts starting with <code>#!</code> or <code>extproc </code> will be executed directly, without calling the shell, by calling the program specified on the rest of the first line.</p>

</li>
</ul>

<h2 id="Memory-allocation"><a class="permalink" href="perlos2.html#Memory-allocation">#</a><a id="Memory"></a>Memory allocation</h2>

<p>Perl uses its own malloc() under OS/2 - interpreters are usually malloc-bound for speed, but perl is not, since its malloc is lightning-fast. Perl-memory-usage-tuned benchmarks show that Perl&#39;s malloc is 5 times quicker than EMX one. I do not have convincing data about memory footprint, but a (pretty random) benchmark showed that Perl&#39;s one is 5% better.</p>

<p>Combination of perl&#39;s malloc() and rigid DLL name resolution creates a special problem with library functions which expect their return value to be free()d by system&#39;s free(). To facilitate extensions which need to call such functions, system memory-allocation functions are still available with the prefix <code>emx_</code> added. (Currently only DLL perl has this, it should propagate to <i>perl_.exe</i> shortly.)</p>

<h2 id="Threads"><a class="permalink" href="perlos2.html#Threads">#</a>Threads</h2>

<p>One can build perl with thread support enabled by providing <code>-D usethreads</code> option to <i>Configure</i>. Currently OS/2 support of threads is very preliminary.</p>

<p>Most notable problems:</p>

<dl>

<dt id="COND_WAIT"><a class="permalink" href="perlos2.html#COND_WAIT">#</a><code>COND_WAIT</code></dt>
<dd>

<p>may have a race condition (but probably does not due to edge-triggered nature of OS/2 Event semaphores). (Needs a reimplementation (in terms of chaining waiting threads, with the linked list stored in per-thread structure?)?)</p>

</dd>
<dt id="os2.c"><a class="permalink" href="perlos2.html#os2.c">#</a><a id="os2"></a><i>os2.c</i></dt>
<dd>

<p>has a couple of static variables used in OS/2-specific functions. (Need to be moved to per-thread structure, or serialized?)</p>

</dd>
</dl>

<p>Note that these problems should not discourage experimenting, since they have a low probability of affecting small programs.</p>

<h1 id="BUGS"><a class="permalink" href="perlos2.html#BUGS">#</a>BUGS</h1>

<p>This description is not updated often (since 5.6.1?), see <i>./os2/Changes</i> for more info.</p>

<h1 id="AUTHOR"><a class="permalink" href="perlos2.html#AUTHOR">#</a>AUTHOR</h1>

<p>Ilya Zakharevich, cpan@ilyaz.org</p>

<h1 id="SEE-ALSO"><a class="permalink" href="perlos2.html#SEE-ALSO">#</a><a id="SEE"></a>SEE ALSO</h1>

<p>perl(1).</p>


      </div>
      <div id="footer">
        <p>Perldoc Browser is maintained by Dan Book (<a href="https://metacpan.org/author/DBOOK">DBOOK</a>). Please contact him via the <a href="https://github.com/Grinnz/perldoc-browser/issues">GitHub issue tracker</a> or <a href="mailto:dbook@cpan.org">email</a> regarding any issues with the site itself, search, or rendering of documentation.</p>

<p>The Perl documentation is maintained by the Perl 5 Porters in the development of Perl. Please contact them via the <a href="https://github.com/Perl/perl5/issues">Perl issue tracker</a>, the <a href="https://lists.perl.org/list/perl5-porters.html">mailing list</a>, or <a href="https://kiwiirc.com/client/irc.perl.org/p5p">IRC</a> to report any issues with the contents or format of the documentation.</p>


      </div>
    </div>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.slim.min.js" integrity="sha512-/DXTXr6nQodMUiq+IUJYCt2PPOUjrHJ9wFrqpJ3XkgPNOZVfMok7cRw6CSxyCQxXn6ozlESsSh1/sMCTF1rL/g==" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.1/umd/popper.min.js" integrity="sha512-ubuT8Z88WxezgSqf3RLuNi5lmjstiJcyezx34yIU2gAHonIi27Na7atqzUZCOoY4CExaoFumzOsFQ2Ch+I/HCw==" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script>
    <script src="../highlight.pack.js"></script>
    <script>hljs.highlightAll();</script>
  </body>
</html>
